I have write a program to read 6 numbers and find the average of all odd numbers. here is my code

``````Scanner get = new Scanner (System.in);

double average = 0, counter = 0 ;
int i, num = 0, sum = 0, count = 0, total = 0;

for(i=0; i<=5; i++)
{

if(i % 2 == 1)
{

count++;
sum += num;

}
}
System.out.println("the sum of odd numbers is "+ total);
System.out.println("the average is " + average);
``````

I tried different approach and still not getting it to work, this is my last approach for now. can u tell me where i am going wrong here.

Firstly, i is just an integer that you use to loop through with. It isn't the collection of numbers that the user entered. So checking
`if(i % 2 == 1)`

## All 3 Replies

Firstly, i is just an integer that you use to loop through with. It isn't the collection of numbers that the user entered. So checking
`if(i % 2 == 1)`
Also one more hint... Your code has no input from user. You need to add that and use the input to determine your results, not `i`.