-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalpha.java
38 lines (32 loc) · 976 Bytes
/
alpha.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
import java.util.Arrays;
import java.util.Scanner;
public class alpha
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the number of elements ");
n=sc.nextInt();
String country[]=new String[n];
System.out.println("Enter the String ");
Scanner sc1=new Scanner(System.in);
for(int i=0; i<n ;i++)
{
country[i]=sc1.nextLine();
}
for(int i = 0; i<n; i++)
{
for (int j = i+1; j<n; j++)
{
if(country[i].compareTo(country[j])>0)
{
String temp = country[i];
country[i] = country[j];
country[j] = temp;
}
}
}
System.out.println(Arrays.toString(country));
}
}