write a program that will display all the odd numbers between 1 and 15. here is the code that i used
Scanner scan = new Scanner (System.in);
int i, num=0, count_odd = 0;
for(i=1; i<=15; i++)
{
System.out.println("please enter number ");
num = scan.nextInt();
}
if(num%2!=0)
{
count_odd++;
}
System.out.println("The number of odd numbers entered were " + count_odd);
and here is the result when i run it. would like to know if it is the wrong or right code and if it is the wrong code where do i went wrong.
here is the result.
please enter number
1
please enter number
2
please enter number
3
please enter number
4
please enter number
5
please enter number
6
please enter number
7
please enter number
8
please enter number
9
please enter number
10
please enter number
11
please enter number
12
please enter number
13
please enter number
14
please enter number
15
The number of odd numbers entered were 1
BUILD SUCCESSFUL (total time: 33 seconds)
the program is supposed to display only odd numbers only. dont where I am wrong