写java程序

时间:2014-11-04 19:05:59

标签: java

import java.util.Scanner;
public class treasure
{
   public static void main(String[] args)
   {


     Scanner variable=new Scanner(System.in);

     int a,b,c,d,e,f,g,h,i,j;
a=variable.nextInt();
b=variable.nextInt();
c=variable.nextInt();
d=variable.nextInt();
e=variable.nextInt();
f=variable.nextInt();
g=variable.nextInt();
h=variable.nextInt();
i=variable.nextInt();
j=variable.nextInt();
while(variable%2==0)
{

          System.out.println("its an even number"+a);
System.out.println("its an even number"+b);
System.out.println("its an even number"+c);
System.out.println("its an even number"+d);
System.out.println("its an even number"+e);
System.out.println("its an even number"+f);
System.out.println("its an even number"+g);
System.out.println("its an even number"+h);
System.out.println("its an even number"+i);
System.out.println("its an even number"+j);

}

System.out.println("its an odd number");
}

}

编写java程序,在奇数或偶数运行时测试中读取10个int数 (如果它甚至打印出偶数,否则奇数) 我只允许使用(while - do while - for)

1 个答案:

答案 0 :(得分:0)

因为我有做家庭作业的心情!您的代码应该是:

Scanner variable=new Scanner(System.in);
int counter=0;
while(counter<10) {
   if(variable.nextInt()%2==0){
       System.out.println("its an even number.");
   } else {
       System.out.println("its an odd number.");
   }
        counter++;
}