判断语句也没错吧,可是如果输入(1-5)之外的任何字母或数字do-while循环都会执行三次不知道为什么,请教高手解答importjava.io.IOException;publicclassTestDoWhile{publicstaticvo...
判断语句也没错吧,可是如果输入(1-5)之外的任何字母或数字do-while循环都会执行三次不知道为什么,请教高手解答
import java.io.IOException;
public class TestDoWhile {
public static void main(String args[]) throws IOException{
char choice = 0 ;
do{
System.out.println("Help on:");
System.out.println("1.if");
System.out.println("2.switch");
System.out.println("3.while");
System.out.println("4.do-while");
System.out.println("5.for");
System.out.println("Choice one:");
choice=(char)System.in.read();
}while(choice'5');
System.out.println("******************");
switch(choice){
case'1':
System.out.println("The if:");
System.out.println("if(condition)statement;");
System.out.println("else statement");
break;
case'2':
System.out.println("The switch:");
System.out.println("switch(expression){");
System.out.println("case constant:");
System.out.println("statement sequence");
System.out.println("break;");
System.out.println("//...");
System.out.println("}");
break;
case'3':
System.out.println("The while:");
System.out.println("while(condition)"+"statement;");
break;
case'4':
System.out.println("The do-while:");
System.out.println("do{");
System.out.println("statement");
System.out.println("}while(condition);");
break;
case'5':
System.out.println("The for:");
System.out.println("for(int;condition;"+"iteration)");
System.out.println("statement;");
break;
}
}
}
展开