-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSortedOrder.java
More file actions
44 lines (37 loc) · 1.15 KB
/
StringSortedOrder.java
File metadata and controls
44 lines (37 loc) · 1.15 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
42
43
44
import java.util.Scanner;
public class StringSortedOrder
{
public static void main(String[] args)
{
int count;
String temp;
Scanner scan = new Scanner(System.in);
System.out.print("Enter number of strings you would like to enter:");
count = scan.nextInt();
String str[] = new String[count];
Scanner scan2 = new Scanner(System.in);
System.out.println("Enter the Strings one by one:");
for(int i = 0; i < count; i++)
{
str[i] = scan2.nextLine();
}
for (int i = 0; i < count; i++)
{
for (int j = i + 1; j < count; j++) {
if (str[i].compareTo(str[j])>0)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
System.out.print("Strings in Sorted Order:");
for (int i = 0; i <count ; i++)
{
System.out.print(str[i] + ", ");
}
scan.close();
scan2.close();
}
}