ICSE Class 9 Computer Applications
Question 11 of 29
Iterative Constructs in Java — Question 14
Back to all questions 14
Question Question 10
Write a program using do-while loop to compute the sum of the first 50 positive odd integers.
public class KboatSumOdd
{
public static void main(String args[]) {
long sumOdd = 0;
int i = 1;
do {
sumOdd += i;
i += 2;
} while(i <= 50);
System.out.println("Sum of 50 odd positive numbers = " + sumOdd);
}
}Output
