-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanCheck.java
More file actions
29 lines (27 loc) · 1.02 KB
/
Copy pathBooleanCheck.java
File metadata and controls
29 lines (27 loc) · 1.02 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
/*This Java program reads four boolean values from the user and prints "Hello" if
at least two of them are true; otherwise, it prints "Goodbye".*/
import java.util.Scanner;
public class BooleanCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter 1st bool value(true/false): ");
boolean a = scanner.nextBoolean();
System.out.print("Enter 2nd bool value for b (true/false): ");
boolean b = scanner.nextBoolean();
System.out.print("Enter 3rd bool value for c (true/false): ");
boolean c = scanner.nextBoolean();
System.out.print("Enter 4th bool value for d (true/false): ");
boolean d = scanner.nextBoolean();
int entry = 0;
if (a) entry++;
if (b) entry++;
if (c) entry++;
if (d) entry++;
if (entry >= 2) {
System.out.println("Hello");
}
else {
System.out.println("Goodbye");
}
}
}