-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathSortingName.java
38 lines (36 loc) · 916 Bytes
/
SortingName.java
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
/* Sort name by dictionary order
Input
-----------------
Arijit
Minaz
Arnab
Output
-------------------
Arijit
Arnab
Minaz
*/
import java.util.*;
public class SortingName {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = new String[3];
String name = "";
for (int i = 0; i < str.length; i++) {
str[i] = sc.nextLine();
}
for (int i = 0; i < str.length; i++) {
for (int j = i+1; j < str.length; j++) {
if(str[i].compareTo(str[j])>0)
{
name = str[i];
str[i]=str[j];
str[j]=name;
}
}
}
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}