Program that will find Largest Number from given Three Numbers
Method 1
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
if(a>b){
if(a>c){
System.out.println("a is Largest");
}else
{
System.out.println("c is Largest");
}
}else{
if(b>c){
System.out.println("b is Largest");
}else{
System.out.println("c is Largest");
}
}
}
}
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
import java.util.*;
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
Scanner in = new Scanner(System.in);
System.out.print("Enter a b and c Number ==> ");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
import java.util.*;
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = Integer.parseInt(args[2]);
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
import java.util.*;
class LargestThreeNo{
int large;
LargestThreeNo()
{
int a,b,c;
Scanner in = new Scanner(System.in);
System.out.print("Enter a b and c Number ==> ");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
}
void display()
{
System.out.println("Largest No ==> " + large);
}
}
class main{
public static void main(String args[]){
LargestThreeNo l =new LargestThreeNo();
l.display();
}
}
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
if(a>b){
if(a>c){
System.out.println("a is Largest");
}else
{
System.out.println("c is Largest");
}
}else{
if(b>c){
System.out.println("b is Largest");
}else{
System.out.println("c is Largest");
}
}
}
}
Output
c is Largest
Method 2
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
Output
Largest No ==> 30
Method 3
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
Scanner in = new Scanner(System.in);
System.out.print("Enter a b and c Number ==> ");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
Output
Enter a b and c Number ==> 10 20 30
Largest No ==> 30
Method 4
class LargestThreeNo{
public static void main(String args[]){
int a=10,b=20,c=30;
int large;
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = Integer.parseInt(args[2]);
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Largest No ==> " + large);
}
}
Output
Method 5
class LargestThreeNo{
int large;
LargestThreeNo()
{
int a,b,c;
Scanner in = new Scanner(System.in);
System.out.print("Enter a b and c Number ==> ");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
large = (a>b)?((a>c)?a:c):((b>c)?b:c);
}
void display()
{
System.out.println("Largest No ==> " + large);
}
}
class main{
public static void main(String args[]){
LargestThreeNo l =new LargestThreeNo();
l.display();
}
}
Output
Enter a b and c Number ==> 10 20 30
Largest No ==> 30

No comments:
Post a Comment