write a program in Java to accept three integer parameter and print the largest of this number
Answers
import java.util.Scanner;
class Largest
{
public static void main (string args [])
{
int x, y, z;
System.out.println ("Enter three intigers");
Scanner in= new Scanner (System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
if (x > y && x > z)
System.out.println("First number is largest");
else if (y > x && y > z)
System.out.println("Second number is largest");
else if (z > x && z > y)
System.out.println("Second number is largest");
}
}
Program :-
import java.util.Scanner;
public class Findlargestof3
{
public static void main(String args [ ] )
{
init maxNum;
Scanner scan = new Scanner(System.in);
System.out.println(''Enter the first number: '');
int num1 = scan.nextInt();
System.out.print(''Enter the second number : '');
int num2 = scan.nextInt();
System.out.println(''Enter the third number : '');
int num3 = scan.nextInt();
maxNum = num1;
if (num2 > maxNum)
maxNum = num2;
if (num3 > maxNum)
maxNum = num3;
System.out.println(''Largest of '' + num1 + '', '' + num2 + '' and '' + num3 + ''is : '' + maxNum);
scan.close();
}
}
Output :-
Enter the fist number : 12
Enter the second number : 56
Enter the third number : 34
Largest of 12, 56 and 34 is : 56