刚开始的Java,Eclipse将的Java重新运行程序做while循环
我希望程序contine只有当“Y”或“Y”按下
如果任何其他键被按下结束程序
请帮助
import java.io.*;
public class TicketMaster{
public static void main(String args[]) throws IOException{
char choice;
do{
choice ='\0'; //clear char
System.out.println("First Test \t\t" + choice);
//rerun program
System.out.println("Run Program Again: ");
choice = (char) System.in.read();
//testing
if(choice == 'y' || choice == 'Y')
System.out.println("Contine \t\t" + choice);
else
System.out.println("End Program \t\t" + choice);
System.out.println("\n\n\n");
}
while(choice == 'y' || choice == 'Y');
} //end main method
} //end class
你仍然没有在每次迭代之间做出选择。如果你输入yyyy并回车,循环将重复4次,然后执行(或循环)结束。 –