Write a Java-program to print MAX Number Amoung 3 Numbers
Program
public class Main
{
public static void main(String args[])
{
int x=10,y=20,z=30
String s;
s=(x > y) ? (x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max");
System.out.println(s);
}
}
Output:
z is Max
Using CommandLine Arguments
public class Main
{
public static void main(String args[])
{
int x,y,z;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
z=Integer.parseInt(args[2]);
String s;
s=(x > y) ? (x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max");
System.out.println(s);
}
}
Output:
z is Max
Using Scanner Class
import java.util.*;
public class Main
{
public static void main(String args[])
{
int x,y,z;
Scanner s1=new Scanner(System.in);
System.out.println("Enter x ,y ,z values");
x=s1.nextInt();
y=s1.nextInt();
z=s1.nextInt();
String s;
s=(x > y) ?
(x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max");
System.out.println(s);
}
}
Output:
Enter x, y, z values
10
20
30
z is Max
More Questions
23 . Write a Java-program to print MAX Number Amoung 3 Numbers
24 . Write a Java-program to print ODD or Even Number using if else condition
25 . Write a Java-program to print max number using if else condtion
26 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3)
27 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4)
28 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4 using 2 conditions)
29 . Write a Java-program to check the given number is valid or invalid(value must between 20 and 30)
30 . Write a Java-program to check the given character is vowel or consonant
31 . Write a Java-program to check the given character is small letter or not
32 . Write a Java-program to check the given character is capital letter or not
33 . Write a Java-program to check the given character is number or not