I need help with this code, my desired output is supposed to be like this
Input an integer:
1
2
3
4
5
6
7
8
9
0
Even numbers are: 0 2 4 6 8
Odd numbers are: 1 3 5 7 9
But my output with this code is like this:
Input an integer: 1
Input an integer: 2
Input an integer: 3
//and so on
Even numbers are 0
Even numbers are 2
Odd numbers are 1
Odd numbers are 3
//and so on
Here's my code
import java.io.*; public class Prelims2{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a, b; int al[] = new int[10]; for(b = 0; b < 10; b++){ System.out.print("Input an integer: "); al[b]=Integer.parseInt(br.readLine()); } for(b = 0; b < 10; b++) if(al[b]%2==0){ System.out.println("Odd numbers are:" +b); } { for(b = 0; b < 10; b++) if(al[b]%2!=0) System.out.println("Even numbers are:" +b); } } }