i am working on a project that involves asking the user for a player's name, and then prompts them yes or no if they have more names to enter, i used a switch statement to handle the yes/no input from the user.
i would like to have loop within the switch statement that would allow me to ask for the next name, ask again if there are more names and then repeat the cycle until the user chooses no.
how would i do so?
switch (names)
{
case 'Y':case 'y': //yes
System.out.println("Next player's name?... " + scan.nextLine());
System.out.println("New player is: " + scan.next());
System.out.println("");
System.out.println("More players? Y/N... "); //* i would like the loop here *//
break;
case 'N':case 'n': //no
System.out.println("You chose NO, program terminated.");
break;
default: //exit program
System.out.println("Not a choice, program terminated.");
if what i want to do can't be done using a switch statement what would be the best approach? tips greatly appreciated.
thanks all

New Topic/Question
Reply




MultiQuote







|