forked from tarnnummulani/java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondLargestNo.java
More file actions
41 lines (38 loc) · 1.09 KB
/
SecondLargestNo.java
File metadata and controls
41 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
public class SecondLargestNo{
public static void largest(int n1, int n2,int n3){
if(n1>n2&n1>n3){
if(n2>n3){
/* ----n1 is greatest number.----*/
System.out.println(n2+" is second greatest number");
}else{
System.out.println(n3+" is second greatest number");
}
}else if(n2>n1&n2>n3){
/* ----n2 is greatest number.----*/
if(n1>n3){
System.out.println(n1+" is second greatest number");
}else{
System.out.println(n3+" is second greatest number");
}
}
else{
/* ----n3 is greatest number.----*/
if(n2>n1){
System.out.println(n2+" is second greatest number");
}else{
System.out.println(n1+" is second greatest number");
}
}
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first no:");
int n1 = sc.nextInt();
System.out.println("Enter the second no:");
int n2 = sc.nextInt();
System.out.println("Enter the third no:");
int n3 = sc.nextInt();
largest(n1,n2,n3);
}
}