-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIT1A_Group13_Lab5.java
More file actions
58 lines (38 loc) · 1.5 KB
/
Copy pathIT1A_Group13_Lab5.java
File metadata and controls
58 lines (38 loc) · 1.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
/**
* EOF Controlled while loop that read some numbers, and get the sum of all odd numbers and sum of all even numbers entered.
* Group 13
* Authors: Lobingco, Kenneth F.
* Islanan, Lenito Laurencio Lamberto
* Laboratory Exercise 5
* Date: April 25, 2021
*/
public class IT1A_Group13_Lab5
{
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
int number;
int sumEven = 0;
int sumOdd = 0;
int i = 1, countEven = 0, countOdd = 0;
System.out.println("Please enter a number: (To end the input, press ctrl + z)");
while (input.hasNext()) {
number = input.nextInt();
while (number > 0) {
int rem = number % 10;
if (rem % 2 == 0)
sumEven += number % 10;
if (rem % 2 == 0)
countEven++;
if (rem % 2 != 0)
sumOdd = sumOdd + number % 10;
number /= 10;
if (rem % 2 != 0)
countOdd++;
}
i++;
}
System.out.println("The sum of the " + countEven + " even numbers read = " + sumEven);
System.out.println("The sum of the " + countOdd + " odd numbers read = " + sumOdd);
}
}