Computer Applications

Write a program using do-while loop to compute the sum of the first 50 positive odd integers.

Java

Java Iterative Stmts

11 Likes

Answer

public class KboatSumOdd
{
    public static void main(String args[]) {
        long sumOdd = 0;      
        for (int i = 1; i <= 50; i++) 
                if (i % 2 != 0)
                    sumOdd += i;
                    
        System.out.println("Sum of 50 odd positive numbers = " + sumOdd);        
    }
}

Output

Answered By

4 Likes


Related Questions