Nama Anggota Kelompok :
Amiriyanti
D03112005
Rini Apriyani
D03112033
Duwi Juliyatin D03112059
"Algoritma dan Pemrograman
untuk Mengurutkan Angka dengan Metode Bubble Sort"
1. Algoritma
x[length]
x[0] = 2
x[1] = 1
x[2] = 9
x[3] = 5
for (int b = 0 ; b≤3 ; b++)
for (int a = b+1 ; a≤9 ; a++)
if (x[b] > x[a])
begin
int temp = x[b]
x[b] = x[a]
x[a] = temp;
2. Source code pada Java
import java.util.Scanner;
public class bubble{
public static void main(String[] args){
// instansiasi variabel scanner
Scanner i = new Scanner(System.in);
int[] angka = new int[10];
for(int a = 0; a <= 9; a++){
System.out.print("Masukan angka ke-"+(a+1)+" : ");
angka[a] = i.nextInt();
}
for (int x = 0; x <= 8; x++) {
for (int y = x+1; y<= 9; y++) {
if(angka[x] > angka[y]){
int temp = angka[x];
angka[x] = angka[y];
angka[y] = temp;
}
}
}
}
}
for (int t = 0;t < angka.length ; t++ ) {
System.out.println("Angka ke-"+(t+1)+" : "+angka[t]);
}
}
}
}
No comments:
Post a Comment