It is impossible to output even and odd numbers on one line:

int n = key.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = (int) (Math.random() * 100); System.out.print(a[i] + " "); } System.out.println(); for (int i = 0; i < a.length; i++) { if (a[i]%2==0) { System.out.println("even="+a[i]+" "); } } System.out.println(); for (int i = 0; i < a.length; i++) { if (a[i]%2!=0) { System.out.println("odd="+a[i]+" "); } } 

Direct in the right direction.

  • 2
    I deleted the arraylist label until you tell me where it is - Alexey Shimansky

1 answer 1

Instead of println , you probably need to use print . Then everything will be printed on one line.