Computer Science, asked by Anonymous, 5 hours ago

Wap a program using while loop to calculate the sum of first 50 even and odd integers.
(brainlyprogrammer, copythat, anindyaadhikari13)

Answers

Answered by CopyThat
7

Program :-  {JAVA}

public class OddEvenSum

{

public static void main(String args [ ])

{

int i = 1;

int sumEven = 0, sumOdd = 0;

while (i <=50)

{

if (i % 2 ==0)

sumEven += i;

else

sumOdd += i;

i++;

}

System.out.println(''The sum of even numbers is '' + sumEven);

System.out.println(''The sum of odd number is '' + sumOdd);

}

}

Output :-

The sum of even numbers is 650

The sum of odd numbers is 625

Similar questions