▪︎Write to find the greatest out of three input numbers ▪︎《using if else ladder》Please answer my question..☠
no spam☠
Answers
printf("num3 is the greatest among three \n");
Take the three numbers and store it in the variables num1, num2 and num3 respectively.
Firstly check if the num1 is greater than num2.
If it is, then check if it is greater than num3.
If it is, then print the output as “num1 is the greatest among three”.
import java.util.Scanner;
public class LargestNumber {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter three numbers - ");
int numOne = sc.nextInt( ),
numTwo = sc.nextInt( ),
numThree = sc.nextInt( ),
largestNum;
if (numOne > numTwo && numOne > numThree)
largestNum = numOne;
else if (numTwo > numThree)
largestNum = numTwo;
else largestNum = numThree;
System.out.println("Largest number - " + largestNum);
}
}