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...

Write a program that will read sentences from a text file, placing each sentence in its own instance of ArrayList. (You will create a sentence object by adding words to it one at a time as they are read.) When a sentence has been completely read, add the sentence to another instance of ArrayList. Once you have read the entire file, you will have an instance of ArrayList that contains several instances of ArrayList, one for each sentence read. Now ask the user to enter a sentence number and a word number. Display the word that occurs in the given position. If the sentence number or word number is not valid, provide an appropriate error message.

What will be an ideal response?

Computer Science & Information Technology

Which key converts the Pen tool to the Convert Anchor Point tool using a Windows machine?

A. [Alt] B. [Shift] C. [Ctrl] D. [Tab]

Computer Science & Information Technology

In a large database, it is impossible to retrieve just the data that you need because there is no way to filter databases

Indicate whether the statement is true or false

Computer Science & Information Technology

If you want to search for customers who meet certain criteria, such as those who live in all states except Arizona, Nevada, or New Mexico, you would type ________("Arizona", "Nevada", "New Mexico") as the criterion in the State field

A) Like B) Between...And C) Not In D) Not Between...And

Computer Science & Information Technology