Skip to content

Commit 424db51

Browse files
committed
feat: Add And1 class using nested if statements for divisibility check
Add a program that: - Takes two integer inputs from the user - Checks divisibility by 3 and 5 using nested if statements instead of logical operators - Demonstrates an alternative approach to compound condition evaluation - Outputs whether each number is divisible by both 3 and 5.
1 parent 4f0177b commit 424db51

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Section5OperatorExpression/src/And1.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
public class And1 {
44
public static void main(String[] args) {
5-
Scanner scanner = new Scanner(System.in);
5+
Scanner sc = new Scanner(System.in);
66

7-
// Read the first number
8-
int num1 = scanner.nextInt();
7+
System.out.printf("Enter a Number: ");
8+
int num1 = sc.nextInt();
99
if (num1 % 3 == 0) {
1010
if (num1 % 5 == 0) {
1111
System.out.println("Divisible by both 3 and 5");
@@ -16,8 +16,8 @@ public static void main(String[] args) {
1616
System.out.println("Not divisible by both 3 and 5");
1717
}
1818

19-
// Read the second number
20-
int num2 = scanner.nextInt();
19+
System.out.println("Enter a Number: ");
20+
int num2 = sc.nextInt();
2121
if (num2 % 3 == 0) {
2222
if (num2 % 5 == 0) {
2323
System.out.println("Divisible by both 3 and 5");
@@ -28,6 +28,6 @@ public static void main(String[] args) {
2828
System.out.println("Not divisible by both 3 and 5");
2929
}
3030

31-
scanner.close(); // Close the scanner
31+
sc.close(); // Close the scanner
3232
}
3333
}

0 commit comments

Comments
 (0)