hasil running :
listing program :
class sortarray{
public static void main(String[]args){
int []array={16,10,7,6,5,19,60,45,23,76,78,65,43,21,12,83,73,56,
48,79};//memasukan nilai array sbnyak 20
System.out.println("jumlah nilai="+array.length);//menampilkan jumlah array
System.out.println("\nnilai sebelum di urutkan yaitu:");
for(int i=0;i<array.length;i++){
System.out.print(array[i]+" ");//menampilkan nilai yg belum terurut
}
//Proses bubble sort
int temp;
for(int i=0;i<19;i++){
for(int k=19;k>i;k--){
if(array[i]>array[k]){
temp=array[i];
array[i]=array[k];
array[k]=temp;
}
}
}
System.out.println("\n\nnilai sesudah diurutkan yaitu:");
for(int l=0;l<array.length;l++){
System.out.println(array[l]);
}
System.out.print("\n");
}
}
0 komentar:
Posting Komentar