pengurutan data
PENGURUTAN DATA
NAMA: SYURAINI NOOR CHAMSYAH
NPM: 22082010033
KELAS: PARALEL A
MATA KULIAH: BAHASA PEMROGRAMAN
DOSEN PENGAMPU: NUR CAHYO WIBOWO, S.KOM, M.KOM.
Source code
package pengurutan.data;
public class PengurutanData {
public static void main(String[] args) {
//program pengurutan data menggunakan buble short
String menu[]={"sate", "bakso","rendang","soto","nasgor"};
int harga[]={15000,20000,13000,12000,17000};
System.out.println("=============================================");
System.out.println("HARGA MENU MAKANAN");
System.out.println("=============================================");
System.out.println("1.sate=Rp. 15.000");
System.out.println("2.bakso= Rp.20.000");
System.out.println("3.rendang=Rp. 13.000");
System.out.println("4.soto= Rp. 12.000");
System.out.println("5.nasgor=Rp. 17.000");
//sorting bubble
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if(harga[j]<harga[j+1]){
//swap
int swap=harga[j];
harga[j]=harga[j+1];
harga[j+1]=swap;
//sort menu
String temp=menu[j];
menu[j]=menu[j+1];
menu[j+1]=temp;
}
}
}
System.out.println("=============================================");
System.out.println("urutkan menu dari harga tertinggi ke terendah");
System.out.println("=============================================");
System.out.println("Daftar menu makanan");
System.out.println("=============================================");
for (int i = 0; i < 5; i++) {
System.out.println(menu[i]+"="+harga[i]);
}
}
}
screenshoot hasil run
Tracking program:
https://drive.google.com/file/d/1_At8ix6iTXJZ7FSHwdyqmLp4mqRHNDsQ/view?usp=share_link
Komentar
Posting Komentar