Wap a program using while loop to calculate the sum of first 50 even and odd integers.
(brainlyprogrammer, copythat, anindyaadhikari13)
Answers
Answered by
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
Math,
10 days ago
Hindi,
22 days ago
Social Sciences,
22 days ago
English,
8 months ago
Math,
8 months ago