2007年5月26日 星期六

Java Exercise for while

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class loop{
loop() throws NumberFormatException, IOException{
execute();
}
private void execute() throws NumberFormatException, IOException{
int repeat=1;
while(repeat==1? true:false){
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
System.out.println("\nInput a number to tell if it is odd or even.\nCommand Line :>");

String str=br.readLine();
if(str.equals("exit")){
repeat=0;
break;
}
System.out.println("It is a "+((Integer.parseInt(str))%2==1?"Odd":"Even")+" Number");
//repeat=(Integer.parseInt(str))==-1?0:1;



}
System.out.println("Section Terminated");
}


}

沒有留言: