【发布时间】:2015-01-08 20:10:02
【问题描述】:
我正在尝试验证输入值以仅传递可被 10 整除的整数。下面的代码失败了。
public static void main(String args[]) {
Scanner scan =new Scanner(System.in);
ArrayList<Integer> liste = new ArrayList<Integer>(); // I have filled my array with integers
int x=scan.nextInt();
int y=x%10;
do{
if(y==0){
liste.add(x);}
else if(y!=0){
System.out.println("It is not valid"); continue;
}
else
{System.out.println("Enter only integer"); continue;
}
}while(scan.hasNextInt()); }
System.out.println(liste);
System.out.println("Your largest value of your arraylist is: "+max(liste));
【问题讨论】:
-
enter code herepublic static void main(String args[]){是无效的方法签名;) -
为什么不将
scan.nextInt()的结果存储在一个变量中,而不是调用它两次?
标签: java loops if-statement try-catch