In this program, You will learn how to find the largest of three numbers using nested if statement in java.
10 20 30 => 30
40 20 30 => 40
import java.util.Scanner;
class Main {
public static void main(String args[]) {
int a, b, c;
Scanner sc = new Scanner(System.in);
System.out.print("Enter three numbers:");
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if (a > b) {
if (a > c) {
System.out.print("Largest is:" + a);
} else {
System.out.print("Largest is:" + c);
}
} else {
if (b > c) {
System.out.print("Largest is:" + b);
} else {
System.out.print("Largest is:" + c);
}
}
}
}
Enter three numbers:20 10 60
Largest is:60