java判斷如何讓它繼續(xù)下去
package ifu;
import java.util.Scanner;
public class ifu {
public static void main(String[] args){
Scanner input=new Scanner (System.in);
System.out.println("請輸入成績:");
int score=input.nextInt();
if(score%2==0){
System.out.println("偶數(shù)");
}else{
System.out.println("奇數(shù)");
}
}
}輸入以后就不能繼續(xù)輸入了,怎么改寫。
2017-02-19
使用while循環(huán):
public class Helloworld{
? ? public static void main(String[] args){
? ? Scanner input = new Scanner(System.in);
? ? System.out.println("請輸入成績:");
? ? int score = input.nextInt();
? ? while(true){
? ? if( score % 2 == 0){
? ? System.out.println("偶數(shù)");
? ? }
? ? else{
? ? System.out.println("奇數(shù)");
? ? }
? ? System.out.println("請輸入成績:");
? ? score = input.nextInt();
? ? }
? ? }
}