-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay-04-Java-Q22
More file actions
65 lines (50 loc) · 1.39 KB
/
Day-04-Java-Q22
File metadata and controls
65 lines (50 loc) · 1.39 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
57
58
59
60
61
62
63
64
65
/*Seela wants to find the sum of even and odd numbers in the between range values.could you please help her to implements the program.
Input Format
Input consists of two integer.
Constraints
Given N is greater than 1 and lesser than 100.
Output Format
Print the sum of even num and odd num.
Sample Input 0
3
9
Sample Output 0
The Even Sum value is 18.00
The Odd Sum value is 24.00
Sample Input 1
11
23
Sample Output 1
The Even Sum value is 102.00
The Odd Sum value is 119.00
Sample Input 2
100
200
Sample Output 2
Invalid Input*/
#Answer
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start = sc.nextInt();
int end = sc.nextInt();
if(start <= 1 || end >= 100) {
System.out.println("Invalid Input");
return;
}
double evenSum = 0;
double oddSum = 0;
for(int i = start; i <= end; i++) {
if(i % 2 == 0) {
evenSum += i;
} else {
oddSum += i;
}
}
System.out.printf("The Even Sum value is %.2f\n", evenSum);
System.out.printf("The Odd Sum value is %.2f", oddSum);
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
}
}