Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.
What will be an ideal response?
```
public class sumEvenOdd
{
public static void main(String[] args)
{
int evenSum = 0;
int oddSum = 0;
//loop through the numbers
for(int i=1; i <= 25; i++)
{
if(i % 2 == 0)
{
//even number
evenSum += i;
}
else
{
oddSum += i;
}
}
//Output the results
System.out.println("Even sum = " + evenSum);
System.out.println("Odd sum = " + oddSum);
}
}
```
Computer Science & Information Technology
You might also like to view...
The isxdigit function would return false on:
a. a b. A c. 2 d. g
Computer Science & Information Technology
The __________ function concatenates the contents of one C-string with another C-string.
a. strcopy b. strappend c. strcat d. stradd e. None of these
Computer Science & Information Technology