Java Program to Find Largest of Three Numbers
Here you will get java program to find largest of three numbers using if else statements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.util.Scanner; public class LargestNumber { public static void main(String...s){ int x, y, z, largest; Scanner sc = new Scanner(System.in); System.out.println("Enter three numbers:"); x = sc.nextInt(); y = sc.nextInt(); z = sc.nextInt(); largest = x; if(y > x && y > z){ largest = y; } else if(z > x && z > y){ largest = z; } System.out.println("Largest number is " + largest); } } |
Output Enter three numbers: 4 10 5 Largest number is 10