Forum Latihan Pengurutan Data
Source Code :
public static void main(String[] args) {
String[] makanan = new String[5];
int harga[] = new int[5];
System.out.println("=========================================");
System.out.println("|| ||");
System.out.println("|| TALIA APRIANTI ||");
System.out.println("|| 22082010035/NPM GANJIL ||");
System.out.println("|| ||");
System.out.println("=========================================");
System.out.println("=========| B U B B L E S O R T |========");
System.out.println("=========================================");
for (int i = 0; i <= 4; i++) {
makanan[0] = " Bakso "; harga[0] = 11000;
makanan[1] = " Ayam Bakar "; harga[1] = 10000;
makanan[2] = " Gado - Gado "; harga[2] = 13000;
makanan[3] = " Rujak Cingur "; harga[3] = 15000;
makanan[4] = " Mie Ayam "; harga[4] = 11000;
}
System.out.println("_________________________________________");
System.out.println("");
System.out.println(" DAFTAR MENU SEBELUM DI SORTING");
System.out.println("_________________________________________");
System.out.println("");
for (int i = 0; i <= 4; i++) {
System.out.println("|| "+ makanan[i] + " Rp." + harga[i] +" ||");
}
System.out.println("");
//LOOPING DESCENDING
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 3; j++) {
if (harga[j] < harga[j + 1]) {
int dummy = harga[j];
String dummy2 = makanan[j];
harga[j] = harga[j + 1];
makanan[j] = makanan[j + 1];
harga[j + 1] = dummy;
makanan[j + 1] = dummy2;
}
}
}
System.out.println("_________________________________________");
System.out.println("");
System.out.println(" MENAMPILKAN HASIL SORTING(DESCENDING)");
System.out.println("_________________________________________");
System.out.println("");
for (int i = 0; i <= 4; i++) {
System.out.println("|| "+ makanan[i] + " Rp." + harga[i] +" ||");
}
System.out.println("=========================================");
}
Komentar
Posting Komentar