-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSum_of_even_&_odd.java
More file actions
63 lines (27 loc) · 834 Bytes
/
Sum_of_even_&_odd.java
File metadata and controls
63 lines (27 loc) · 834 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Write a program to input an integer N and print the sum of all its even digits and all its odd digits separately.
Digits mean numbers, not the places! If the given integer is "13245", even digits are 2 & 4, and odd digits are 1, 3 & 5.
*/
import java.util.Scanner;
class Solution {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
long temp=sc.nextLong();
long sumOdd=0, sumEven=0;
long n=temp;
while(n!=0)
{
long rem=(n%10);
if(rem%2==0)
{
sumEven+=rem;
}
else
{
sumOdd+=rem;
}
n=n/10;
}
System.out.println(sumEven+" "+sumOdd);
}
}