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("偶数");
}else{
System.out.println("奇数");
}
}
}输入以后就不能继续输入了,怎么改写。
使用while循环:
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("偶数");
}
else{
System.out.println("奇数");
}
System.out.println("请输入成绩:");
score = input.nextInt();
}
}
}