Hey guys! I'm back with another problem :(
I'm supposed to make a for loop program that will print only EVEN numbers from 77 down to 11. I also need to get their sum and average.
By the way here's the code I did:
public class Loop_For2 {
public static void main (String[] args) {
double sum = 0f;
int ctr = 1, ctr2 = 0;
for (;ctr<=77; ctr++, ctr2--) {
System.out.println(ctr);
sum += ctr;
ctr++;
}
double ave = (double) sum/ctr2;
System.out.println ("The sum is: " +sum);
System.out.println ("The average is: " +ave);
}
}
I'm not supposed to use 'if'. Thanks again guys!