Bubble sort an array of Strings
Sorts an array of structures by using the bubble sort
AI
AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ソースコード
import java.util.Scanner;
public class bubblesort
{
public static void main(String[] args)
{
String[] Array;
Array=new String[10];
String temp;
Scanner input=new Scanner(System.in);
for(int i=0;i<10;i++){
System.out.println("Give me the name ");
Array[i]=input.next();
}
for(int x=1;x<10;x++)
{
for(int y=0;y<10-x;y++)
{
if(Array[y].compareTo(Array[y+1])>0)
{
temp=Array[y];
Array[y]=Array[y+1];
Array[y+1]=temp;
}
}
}
for(int i=0;i<10;i++){
System.out.println("The sorted values are "+Array[i]);
}
}
}
オリジナルのコメント (3)
Wayback Machineから復元