class ascending
{
public static void main(String[] args)
{
String [] name={"Kamu","Dia","dan","Aku"};
String temp;
System.out.println("//Sebelum Sorting");
for (int i=0; i
{
System.out.println(i+1+" "+name[i]+" ");
}
for (int i=0; i<(name.length-1); i++)
{
for (int j=0; j<(name.length-1); j++)
{
if (name[j].compareTo(name[j+1])>0)
{
temp=name[j+1];
name[j+1]=name[j];
name[j]=temp;
}
}
}
System.out.println("//Sesudah Sorting");
for (int i=0; i
{
System.out.println(i+1+" "+name[i]);
}
}
}
0 comments:
Post a Comment