-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumOfEvenOdd.java
More file actions
43 lines (34 loc) · 959 Bytes
/
Copy pathsumOfEvenOdd.java
File metadata and controls
43 lines (34 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
# a program that reads a set of integers, and then prints the sum of the
even and odd integers.
steps:
-> create a int variable query for sentinal controled while loop
-> create 2 int variable to store even and odd number sum
-> run while loop unlit user quits
-> if input is even, add it to the sum of even numbers
-> else, add it to the sum of odd numbers
-> finally print result
*/
import java.util.Scanner;
public class Main
{
public static void main (String [] args)
{
Scanner sc = new Scanner (System.in);
int sumeven = 0;
int sumodd = 0;
int query = 1;
while (query == 1)
{
int number = sc.nextInt();
if (number % 2 == 0)
sumeven += number;
else
sumodd += number;
System.out.print ("Type 1 to continue: ");
query = sc.nextInt();
}
System.out.println ("Even sum: " + sumeven);
System.out.println ("Odd sum: " + sumodd);
}
}