Vote Up 0 Vote Down

help in console java program

Is this possible? For example. I choose letter "a" for case a, and in case "a" have scNner to go back to menu to choose another letter for case "b"?
Anyone can help me or correct my console java program..

char a, b, c d:
System.out.print("Menu java");
System.out.println("a. INTRO);
Sysyem.out.println("b. Variables");
System.out.println("c. Array");
System.out.println("enter your choice");
Scanner input = new Scanner(system.in);
a = next().charAt(0);
Switch(ans) {
Case "a":
System.out.println("intro java")
System.out.println("do you want to go back to menu");
System.out.print("type Y if YES N if no")
System.out.println("enter your choice");
Scanner input = new Scanner(system.in);
a = next().charAt(0);
Case "b":
System.out.println("VARIABLES")
System.out.println("do you want to go back to menu");
System.out.print("type Y if YES N if no")
System.out.println("enter your choice");
Scanner input = new Scanner(system.in);
a = next().charAt(0);
Case "c":
System.out.println("Array")
System.out.println("do you want to go back to menu");
System.out.print("type Y if YES N if no")
System.out.println("enter your choice");
Scanner input = new Scanner(system.in);
a = next().charAt(0);
}
}
}
flag

Answers


Vote Up 0 Vote Down
Use do while...put switch in loop, in while check whether a== Y..end.
flag | link |
Vote Up 0 Vote Down
It is very simple....you just have to put switch in loop remember the choice input part should also be inside the loop...after that you have to check after exiting the switch whether the input a is y or n...if y then restart the loop else exit program. ..
flag | link |
Vote Up 0 Vote Down
You need to declare a new character variable
"char ans" and that will hold the data of choice
flag | link |

Your Answer

Login before answering

Login with facebook