I have a client-server console based application, in client side I have used switch statement for selecting options such as upload/ download/ change password etc. When user enters one number for suppose
String userchoice = console.readLine("Enter your choice :");
int choice= Integer.parseInt(userchoice);
switch (choice){
case 3:
........
Socket soc = new Socket("localhost", 6007);
String reply;
String client = username;
char newpswd[] = console.readPassword("Enter your new Password :");
String newpwd=new String(newpswd);
char newpswd1[] = console.readPassword("Confirm your new Password :");
String newpwd1=new String(newpswd1);
if(newpwd.equals(newpwd1)) {
........
}
else {
S.O.P ("Passwords don't match");
}
break;
After the process has been finished, then I need to send the user to switch (choice) statement again asking for the option number to enter. I have tried continue, return but none worked for me. return - will return to JVM I suppose, which is exiting the program. As goto is not used in Java, what will be my alternative ?
After the process has been finished, then I need to send the user to switch (choice) statement again
Then you need a loop:
while (!quit) {
String userchoice = console.readLine("Enter your choice :");
...
switch (...) {
...
}
}
do {
...
}while(choice != EXIT_CHOICE);
where EXIT_CHOICE is a constant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With