Change your code as follows:
Change String y to char y
String y
char y
And read the char with y = sc.next().charAt(0) instead of nextLine()
y = sc.next().charAt(0)
nextLine()
Hope it works
2.1m questions
2.1m answers
60 comments
57.0k users