MSc-Y1-S1-W10-Java-review-simple-programs
Q/ product from 1 to n
A/ (body of program)
int result=1;
for (int n=10;n>=1;n--) {
result = result*n;
}
System.out.println(result);
Q/ print sum of all odd numbers from 1 to 50:
hint1: start at 1
hint2: use i+=2
A/ (body of program)
int result = 0;
for(int i=1;i<50;i+=2) {
result = result+i;
}
PSLG Tutorials