Mengurutkan angka dengan JAVA

,

import javax.swing.JOptionPane;

public class UrutDataGUI {

static int [] valueArray (int angka) {

int data [] = new int [angka];

for (int i=0; i

String b = JOptionPane.showInputDialog ("Masukkan data anda ke-" + i + " : ");

data [i] = Integer.parseInt (b);

}

return data;

}

static int [] sortedArray (int [] sortedData) {

for (int i=0; i

for (int j = i; j

if (sortedData[i] > sortedData[j+1]) {

int temp = sortedData[i];

sortedData[i] = sortedData[j+1];

sortedData[j+1] = temp;

}

}

}

return sortedData;

}

static void showArray (int [] sortedData) {

String c = "Data array sebelum diurutkan adalah : \n";

for (int i=0; i

c += sortedData[i] + " ";

}

sortedData = sortedArray (sortedData);

c += "\nData array setelah diurutkan adalah : \n";

for (int y=0; y

c += sortedData[y] + " ";

}

JOptionPane.showMessageDialog (null, c);

}

public static void main (String [] args) {

String a = JOptionPane.showInputDialog ("Masukkan jumlah data anda : ");

int angka = Integer.parseInt (a);

int dataArray [] = valueArray (angka);

showArray (dataArray);

}

}

0 comments: