I'm trying to make my for loop print ODD numbers and print their sum and average.
Here's my code:
public class Loop_For2 {
public static void main (String[] args) {
double sum = 0f;
int ctr = 1, ctr2 = 0;
for (;ctr<=10; ctr++, ctr2++) {
System.out.println(ctr);
sum += ctr;
}
double ave = (double) sum/ctr2;
System.out.println ("The sum is: " +sum);
System.out.println ("The average is: " +ave);
}
}
OH, and I'm not supposed to use 'if'. Thanks again!