-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumEven.java
More file actions
executable file
·33 lines (27 loc) · 947 Bytes
/
Copy pathSumEven.java
File metadata and controls
executable file
·33 lines (27 loc) · 947 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
//********************************************************************************
// SumEven.java reads an integer value and prints the sum of all the even digits
// between 2 and the input value, inclusive.
//********************************************************************************
import java.util.Scanner;
public class SumEven
{
public static void main (String[] args)
{
int value, sum = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter value: ");
value = scan.nextInt();
while (value < 2)
{
System.out.println("Value cannot be less than 2.");
System.out.print("Enter value: ");
value = scan.nextInt();
}
for (int i = 2; i <= value; i+=2)
{
sum += i;
}
System.out.println("The sum of all even integers between 2 and " + value
+ " is: " + sum + ".");
}
}