Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;

public class assign17_q2


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String a[] = new String[40];
int n = a.length;

System.out.println("Enter 40 Names: ");


for (int i = 0; i < n; i++) {
a[i] = in.nextLine();
}

for (int i = 0; i < n - 1; i++) {


int idx = i;
for (int j = i + 1; j < n; j++) {
if (a[j].compareToIgnoreCase(a[idx]) < 0) {
idx = j;
}
}
String t = a[idx];
a[idx] = a[i];
a[i] = t;
}

System.out.println("Sorted Names");
for (int i = 0; i < n; i++) {
System.out.print("\t"+a[i]);
}
}
}

You might also like