import java.util.Scanner;
public class namesort {
public static void main(String []args)
{
Scanner sc =new Scanner(System.in);
System.out.print("How many names you want to sort");
int len=sc.nextInt();
String names[]=new String[len];
String temp=new String();
for(int i=0;i<len;i++)
{
System.out.print("enter "+i+"name");
names[i]=sc.next();
}
//sorting data
for(int outer=0;outer<names.length;outer++)
{
for(int inner=outer+1;inner<names.length;inner++)
{
if(names[outer].compareTo(names[inner])>0)
{
temp=names[outer];
names[outer]=names[inner];
names[inner]=temp;
}
}
}
for(String s:names)
{
System.out.println(s);
}
}
}
public class namesort {
public static void main(String []args)
{
Scanner sc =new Scanner(System.in);
System.out.print("How many names you want to sort");
int len=sc.nextInt();
String names[]=new String[len];
String temp=new String();
for(int i=0;i<len;i++)
{
System.out.print("enter "+i+"name");
names[i]=sc.next();
}
//sorting data
for(int outer=0;outer<names.length;outer++)
{
for(int inner=outer+1;inner<names.length;inner++)
{
if(names[outer].compareTo(names[inner])>0)
{
temp=names[outer];
names[outer]=names[inner];
names[inner]=temp;
}
}
}
for(String s:names)
{
System.out.println(s);
}
}
}
Không có nhận xét nào:
Đăng nhận xét