-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
34 lines (24 loc) · 906 Bytes
/
Main.java
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Variables to store the sum of even and multiples of 4
int multiplesOf4Sum = 0;
// Prompt the user for input until a single number is entered
System.out.println("Enter numbers (enter a non-integer to finish): ");
while (true) {
int inputNumber = scanner.nextInt();
// Check if the number is even
if (inputNumber % 2 != 0) {
break;
}
// Check if the number is a multiple of 4
if (inputNumber % 4 == 0) {
multiplesOf4Sum += inputNumber;
}
}
// Display the sum of multiples of 4
System.out.println("Sum of multiples of 4: " + multiplesOf4Sum);
scanner.close();
}
}