jeudi 8 janvier 2015

How can I validate that input is an integer evenly divisible by ten?

I am trying to validate input values to pass only integers that are divisible by 10. The code below is failing.



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
try{
do {
if(scan.nextInt()%10==0){// I wanna add only vaues which is ending with zero, but I cant add
liste.add(scan.nextInt());} // // only integer values
} while (scan.hasNextInt());
System.out.println(liste);
max(liste);
}catch(NumberFormatException e){ // I dont wanna an exit on my proggaram cuz of other values
System.out.println("Enter only integer");//
}

System.out.println(liste);
System.out.println("Your largest value of your arraylist is: "+max(liste));

Aucun commentaire:

Enregistrer un commentaire