java - How to find even or odd in array? -
how can find or odd in array?
int size; int[] myarray = new int[10]; scanner input = new scanner(system.in); system.out.print("how many numbers enter:"); size = input.nextint(); for(int c = 0; c < size; c++) { system.out.print("enter number:"); myarray[c] = input.nextint(); } input.close(); for(int c = 0; c < size; c++) { system.out.println(myarray[c]); } if(size%2) { system.out.print("sadsadsad"); } } }
use modulus operator check if number or odd. if divide number 2 , reminder 0 number even, otherwise odd.
for(int i=0; < numbers.length; i++){ if(numbers[i]%2 == 0) system.out.println(numbers[i] + " number."); else system.out.println(numbers[i] + " odd number."); }
Comments
Post a Comment