我該如何擺脫無效方法並回到切換方法?如何擺脫無效的方法,如果沒有「返回」;
public static void decrypt() throws FileNotFoundException {
Scanner kbrd = new Scanner(System.in);
System.out.println("Enter Key-file name: ");
String filename = kbrd.nextLine();
System.out.println("Enter Message-filename: ");
String mssgFilename = kbrd.nextLine();
String[] keyArray = loadMessage(filename);
String[] message = loadMessage(mssgFilename);
String[] cipher = xor2(message, keyArray);
String readable = showText(cipher);
System.out.println("The text:" + readable);
return;
}
,然後這裏是切換方法
System.out.println("Encrypt 1.");
System.out.println("Decrypt 2.");
System.out.println("Make Key 3.");
System.out.println("Quit 4.");
Scanner scan = new Scanner(System.in);
String choice = scan.nextLine();
do {
switch (choice) {
case "1":
encrypt();
break;
case "2":
decrypt();
break;
case "3":
makeKey();
break;
}
} while (choice != "4");
問題是,無論我選擇它停留在該方法儘管在最後的return語句,應該不會帶來我回到開關方法?
你的代碼正在做你在問什麼 - 問題是什麼?有些方法阻止? –
你實際上不需要'return;',一旦存在'decrypt',它就會返回到被調用的地方。此外,您可能希望將菜單和「選擇」輸入放入「do-while」循環中 – MadProgrammer
它如何保持?你能更真實地描述真正發生的事情嗎? – khajvah