sry about my English :)
I am new to Java programming and I have a problem with the Scanner. I need to read Int, show some things, and then read the line, so I use sc.nextInt (); show my stuff showMenu (); , and then try to read the line palabra = sc.nextLine ();
Someone told me that I need to use sc.nextLine (); after sc.nextInt (); but I donβt understand why you need it :(
Here is my code:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int respuesta = 1;
showMenu();
respuesta = sc.nextInt();
sc.nextLine();
switch (respuesta){
case 1:
System.out.println("=== Palindromo ===");
String palabra = sc.nextLine();
if (esPalindromo(palabra) == true)
System.out.println("Es Palindromo");
else
System.out.println("No es Palindromo");
break;
}
}
You are so much for your time and help: D
source
share