Skip to content

Commit 4f0177b

Browse files
committed
feat: Add And class to check divisibility using logical AND operator
Add a program that: - Takes two integer inputs from the user - Checks if each number is divisible by both 3 and 5 using the && operator - Prints the result for each input - Demonstrates real-world usage of logical operators with conditions.
1 parent ca7b116 commit 4f0177b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Section5OperatorExpression/src/And.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@ public class And {
44
public static void main(String[] args) {
55
Scanner scanner = new Scanner(System.in);
66

7-
// Read the first number
7+
System.out.println("Enter a Number One: ");
88
int num1 = scanner.nextInt();
9-
if (num1 % 3 == 0 && num1 % 5 == 0) {
9+
//take num1 as a input and checking whether it is divisible by 3 & 5.
10+
11+
if (num1 % 3 == 0 && num1 % 5 == 0)
12+
{
1013
System.out.println("Divisible by both 3 and 5");
1114
} else {
1215
System.out.println("Not divisible by both 3 and 5");
1316
}
1417

15-
// Read the second number
18+
System.out.println("Enter a Number Two: ");
1619
int num2 = scanner.nextInt();
20+
//take num2 and checking same whether it is divisible by 3 & 5.
21+
1722
if (num2 % 3 == 0 && num2 % 5 == 0) {
1823
System.out.println("Divisible by both 3 and 5");
1924
} else {
2025
System.out.println("Not divisible by both 3 and 5");
2126
}
2227

23-
scanner.close(); // Close the scanner
28+
scanner.close(); // Close the scanner and resources.
2429
}
2530
}

0 commit comments

Comments
 (0)