Skip to content

Commit 2c0a6f2

Browse files
committed
feat: Determine the largest of three user-input numbers using multiple approaches
📌 Logic: - Accepts three integers from the user. - Demonstrates three different ways to find the maximum: 1. Manually comparing using if-statements. 2. Using nested conditional checks. 3. Using `Math.max()` for concise comparison. - Prints the largest number among the three. Signed-off-by: Somesh diwan <[email protected]>
1 parent 6ee6b0b commit 2c0a6f2

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Section7ConditionalStatements/Practice/src/Largest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ public static void main(String[] args) {
99
int c = in.nextInt();
1010

1111
// Q: Find the largest of the 3 numbers
12-
// int max = a;
13-
// if (b > max) {
14-
// max = b;
15-
// }
16-
// if (c > max) {
17-
// max = c;
18-
// }
19-
20-
// int max = 0;
21-
// if (a > b) {
22-
// max = a;
23-
// } else {
24-
// max = b;
25-
// }
26-
//
27-
// if (c > max) {
28-
// max = c;
29-
// }
12+
13+
/*int max = a;
14+
if (b > max) {
15+
max = b;
16+
}
17+
if (c > max) {
18+
max = c;
19+
}*/
20+
21+
/*int max = 0;
22+
if (a > b) {
23+
max = a;
24+
} else {
25+
max = b;
26+
}
27+
28+
if (c > max) {
29+
max = c;
30+
}*/
3031

3132
int max = Math.max(c, Math.max(a, b));
3233

0 commit comments

Comments
 (0)