Program Java Mengurutkan Angka
Langsung saja :
class SortingA {
public static void main (String [] lat) {
int temp=0,b,k,i,j;
int a[] = {10,1,9,7,5,6,4,2,3,8};
System.out.println("Sebelum diurutkan :");
for (i=0;i<10;i++){
System.out.print(a[i] + " ");
}
for (b=0;b<10;b++) {
for (k=0;k<9;k++){
if (a[k]>a[k+1]){
temp = a[k];
a[k] = a[k+1];
a[k+1] = temp;
}
}
}
System.out.println("\n\nSetelah diurutkan :");
for (j=0;j<10;j++){
System.out.print(a[j] + " ");
}
}
}
Tampilan :
class SortingA {
public static void main (String [] lat) {
int temp=0,b,k,i,j;
int a[] = {10,1,9,7,5,6,4,2,3,8};
System.out.println("Sebelum diurutkan :");
for (i=0;i<10;i++){
System.out.print(a[i] + " ");
}
for (b=0;b<10;b++) {
for (k=0;k<9;k++){
if (a[k]>a[k+1]){
temp = a[k];
a[k] = a[k+1];
a[k+1] = temp;
}
}
}
System.out.println("\n\nSetelah diurutkan :");
for (j=0;j<10;j++){
System.out.print(a[j] + " ");
}
}
}
Tampilan :
Comments
Post a Comment