0% found this document useful (0 votes)
20 views1 page

Java Selection Sort for Names

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Java Selection Sort for Names

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q. Write a program to input 10 names in a SDA.

Using the selection sort technique,


arrange the names of the array in ascending order and display the sorted array.

import [Link];
public class sel_sort2
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
int i,j,min=0;
String t;
String [] n = new String[10];
[Link]("Enter 10 names:");
for (i = 0; i < 10; i++)
{
n[i] = [Link]();
}
for (i = 0; i <9; i++)
{
min = i;
for (j = i + 1; j < 10; j++)
{
if (n[j].compareTo( n[min])<0)
{
min = j;
}
}

t = n[min];
n[min] = n[i];
n[i] = t;
}

[Link]("Sorted array:");
for (i = 0; i<10; i++)
{
[Link](n[i]);
}
}
}

You might also like