为什么我必须删除/取消input.close();
以允许下一次扫描参与?第二个结束函数inputtwo.close();
是否都关闭了?
对不起我的坏话。我真的很擅长这个东西。
import java.util.Scanner;
public class FieldTesting {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the month number (1 - 12): ");
int month = input.nextInt();
String monthString;
switch (month) {
case 1:
monthString = "January";
break;
case 2:
monthString = "February";
break;
//etc...
default:
monthString = "Invalid month";
break;
}
System.out.println(monthString);
/* Why must I delete this close statement?
input.close();
*/
Scanner inputtwo = new Scanner(System.in);
System.out.println("Start or Stop? ");
String command = inputtwo.nextLine();
switch (command) {
case "start":
System.out.println("Machine Started");
break;
case "stop":
System.out.println("Machine Stopped");
break;
default:
System.out.println("Not a command.");
break;
}
input2.close();
}
}