Bubble Short With Java


Bubble Short With Java

Sering membosankan dulu pas di ajari C++ apalagi kalau bahas yang namanya bubbleshort.
Mungkin itu efek dari kejenuhan saya yang mandang layar itam putih melulu kali yach……

dan disini saya g mau pake layar itam putih,jadi mending kita buat bubbleshort pake java saja,yang GUI nya bagusan dikit😀

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class bubbleSort {
//banyak elemen array integer
final static int Nmax= 10;

public static void Bubble_Ascending (int b[]) {
int temp =0;

for (int i=0;i<=Nmax-2; i++) {
for (int j=Nmax-1; j>=i+1; j–) {
if (b[j] < b[j-1]) {
temp = b[j-1];
b[j-1] = b[j];
b[j] = temp;
}
}
}
}

public static void main (String args []) {
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));

int b[] = new int [Nmax];
try {
//Menerima inputan sebanyak Nmax kali
for (int i=0;i<=Nmax-1;i++) {
System.out.print(“Enter an integer”);
b [i] = Integer.parseInt(in.readLine());
}
Bubble_Ascending(b);

for (int i=0;i<=Nmax-1;i++) {
System.out.print(b[i]+” , “);
}
}
catch (Exception e) {
System.out.println(“ERROR ada kesalahan dalam input”);
}
}
}

3 thoughts on “Bubble Short With Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s