package algorithmsample32;
import java.util.Scanner;
/**
*
* @author Nurhak
*/
public class AlgorithmSample32 {
public static void main(String[] args) {
int number = 0;
int sumEvenNumbers = 0;
int sumOddNumbers = 0;
String data = "";
try {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter 10 numbers.");
for (int i = 1; i <= 10; i++) {
System.out.println("Number : " + i);
data = scan.nextLine();
number = Integer.parseInt(data);
if (number % 2 == 0) {
sumEvenNumbers = sumEvenNumbers + number;
} else {
sumOddNumbers = sumOddNumbers + number;
}
}
System.out.println("Sum of even numbers: " + sumEvenNumbers
+ " Sum of odd numbers: " + sumOddNumbers);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Comments
Post a Comment