Skip to content

Commit 2505077

Browse files
committed
feat: Add And2 class with explicit zero handling in divisibility check
Enhance the divisibility checker by: - Accepting two user inputs - Handling the special case where input is 0 (since 0 is divisible by any number) - Using logical AND (&&) for standard divisibility checks - Providing meaningful output for all cases including edge input.
1 parent 424db51 commit 2505077

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Section5OperatorExpression/src/And2.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class And2 {
44
public static void main(String[] args) {
55
Scanner scanner = new Scanner(System.in);
66

7-
// Read the first number
87
int num1 = scanner.nextInt();
98
if (num1 == 0) {
109
System.out.println("Zero is divisible by both 3 and 5");
@@ -14,7 +13,6 @@ public static void main(String[] args) {
1413
System.out.println("Not divisible by both 3 and 5");
1514
}
1615

17-
// Read the second number
1816
int num2 = scanner.nextInt();
1917
if (num2 == 0) {
2018
System.out.println("Zero is divisible by both 3 and 5");
@@ -24,6 +22,6 @@ public static void main(String[] args) {
2422
System.out.println("Not divisible by both 3 and 5");
2523
}
2624

27-
scanner.close(); // Close the scanner
25+
scanner.close();
2826
}
2927
}

0 commit comments

Comments
 (0)