In Java, we can easily find the largest number among three numbers using conditional statements.
We can use the if-else statement to check which number is the largest.
Here’s a simple Java program that takes three numbers as input and finds the largest among them:
import java.util.Scanner;
public class LargestAmongThreeNumbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter three numbers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int num3 = scanner.nextInt();
int largest = num1;
if (num2 > largest) {
largest = num2;
}
if (num3 > largest) {
largest = num3;
}
System.out.println("Largest number is: " + largest);
}
}In this program, we first import the Scanner class to read input from the user.
Then we prompt the user to enter three numbers.
We declare three integer variables to store the input numbers, num1, num2, and num3.
We also declare another integer variable largest and initialize it with the value of num1, assuming that num1 is the largest among the three.
Next, we use if statements to check if num2 or num3 is larger than largest.
If either of these numbers is larger, we update the value of largest accordingly.
Finally, we print the value of largest as the output, which is the largest among the three input numbers.
This program can be used to find the largest among any three numbers entered by the user.
We can modify it to find the largest among more than three numbers by using loops and arrays.




