If I have multiple Scanner user inputs, how can Scanner read an entire String with spaces? While I have seen multiple answers suggest using Scanner.nextLine()
, I do not want to have to input the integer for choice
and the String phrase
on the same line (which is why I used switch, case
instead of if/else
)
int choice = in.nextInt()
public static void main (String[] args){
Scanner in = new Scanner(System.in);
System.out.println ("welcome to November 1st Homework choices! if you would like to test the SSN condenser, input 1! if you would like to test the 'a' counter, input 2! If you would like to test both, enter 3!");
int choice = in.nextInt();
switch(choice){
...
case 2:
System.out.println("Please input a phrase of any sort to count the number of 'a''s in the phrase! :)");
String phrase = in.next();
System.out.println("The number of 'a's in the phrase is " + CountA(phrase));
break;
case 3:
...
System.out.println("Please input a phrase of any sort to count the number of 'a''s in the phrase! :)");
String phrase2 = in.next();
System.out.println("The number of 'a's in the phrase is " + CountA(phrase2));
break;
default:
System.out.println("YOU MUST ENTER A NUMBER BETWEEN 1 AND 3!! >:(D--");
break;
}
}
I hope I made my question clear, I am quite confused.