How to find greatest of three numbers in JAVA?
How to find greatest of three
numbers in JAVA?
Method -1
import java.util.*;
class great
{
public static void main(String[] args)
{
int a,b,c;
Scanner in=new Scanner(System.in);
System.out.print("\n enter a=");
a=in.nextInt();
System.out.print("\n enter b=");
b=in.nextInt();
System.out.print("\n enter c=");
c=in.nextInt();
if(a>b)
{
if(a>c)
{
System.out.println("a is
greatest");
}
else
{
System.out.println("c is
greatest");
}
}
else
{
if(b>c)
{
System.out.println("b is
greatest");
}
else
{
System.out.println("c is
greatest");
}
}
}
}
Output:
enter a=5
enter b=8
enter c=10
c is greatest
Method-2
import java.util.*;
class great
{
public static void main(String[] args)
{
int a,b,c;
Scanner in=new Scanner(System.in);
System.out.print("\n enter a=");
a=in.nextInt();
System.out.print("\n enter b=");
b=in.nextInt();
System.out.print("\n enter c=");
c=in.nextInt();
if((a>b) && (a>c))
{
System.out.println("a is
greatest");
}
else
{
if((b>c) && (b>a))
{
System.out.println("b is
greatest");
}
else
{
System.out.println("c is
greatest");
}
}
}
}
Output:
enter a=4
enter b=8
enter c=2
b is greatest
How to find greatest of three numbers in JAVA?
Reviewed by Unknown
on
January 28, 2019
Rating:
No comments:
If you have any doubt or query ,comment below: