so, i am looking to write code which firstly asks for user input in order to run the desired operation, this element of my code is working fine, but after selecting one of the options from the first menu i am asking the user for a second string input which i would like to turn to both lower and uppercase, but instead of letting me enter an input, the program just goes back to the original screen showing all options.
this is my code asking for a string input that isnt working:
else if(choice1==1)
{
System.out.println("=================================" "\n" "You have chosen to convert a given string to upper case and lowercase, please enter your string: " "\n");
choice2 = sc.nextLine();
System.out.println("Your lowercase string: " choice2.toLowerCase() "\n" "Your uppercase string: " choice2.toUpperCase);
}
Cheers for the help guys!!
CodePudding user response:
You need to consume the end of line character:
choice1 = sc.nextInt();
sc.nextLine(); // consume the end of line
// Now your program continues as before.
// Probably you have an 'if' here, I don't know, you
// haven't shown it