不懂应该在哪设置输入流的关闭,试了几个地方,但接着循环,本来要输入的就直接程序关闭报错。(也就几个地方可以放close(),可总是搞不定)
package Week2;
import java.util.Scanner;
public class homework4_16 {
public static void main(String[] args) {
String s1 = "Welcome to Java";
String s2 = "Programming is fun";
String s3 = "Welcome to Java";
int i = 1;
do {
System.out.print("输入字母编号a-v:");
Scanner input = new Scanner(System.in);
String ch = input.nextLine();
switch (ch) {
case "a":
System.out.println(s1 == s2);
break;
case "b":
System.out.println(s2 == s3);
break;
case "c":
System.out.println(s1.equals(s2));
break;
case "d":
System.out.println(s1.equals(s3));
break;
case "e":
System.out.println(s1.compareTo(s2));
break;
default:
continue;
}
System.out.print("继续请输入1,退出输入0 :");
i=input.nextInt();
while(i!=1&&i!=0) {
System.out.print("请输入1或0 :");
i=input.nextInt();
}
} while (i == 1);
}
}