Greatest5.java
Aim:
To find greatest among 5 numbers using else-if ladder
Source code:
import java.util.*;
import java.lang.*;
class Greatest5
{
public static void main(String args[])
{
int a,b,c,d,e;
Scanner input=new Scanner(System.in);
System.out.println("Enter values for a,b,c,d,e");
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
d=input.nextInt();
e=input.nextInt();
if(a>b && a>c && a>d && a>e)
System.out.println("a is greater");
else if(b>a && b>c && b>d && b>e)
System.out.println("b is greater");
else if(c>a && c>b && c>d && c>e)
System.out.println("c is greater");
else if(d>a && d>b && d>c && d>e)
System.out.println("d is greater");
else
System.out.println("e is greater");
}
}
Output-1:
Enter values for a,b,c,d,e
12
5
6
9
11
Output-2:
Enter values for a,b,c,d,e
-15
11
34
-7
-243
c is greater
No comments:
Post a Comment