Program Sortir Data

/**

* @(#)Tugas2.java

*

*

* @author IrwanChortex

* @version 1.00 2010/7/4

*/

//Mengurutkan Data

public class Tugas2

{

public static void main (String[]args)

{

int[] angka = new int[7];

//Inisialisasi Array

for (int i=0;i

angka[i] = (int)(Math.random()*100);

//Menampilkan Data Awal

System.out.println("---------------------------");

System.out.println("Data Sebelum Disortir :");

System.out.println("---------------------------");

for (int i=0;i

System.out.println(angka[i]+ " ");

System.out.println("---------------------------");


//Proses Sortir Dengan Selection Sort

for (int x=0;x

for (int y=x+1;y

if (angka[x]>angka[y])

{

int bantu=angka[x];

angka[x]=angka[y];

angka[y]=bantu;

}

//Menampilkan data

System.out.println("\n\n---------------------------");

System.out.println("Data Setelah "+"Sortir :");

System.out.println("---------------------------");

for (int i=0;i

System.out.print(angka[i]+" ");

System.out.println();

System.out.println("---------------------------");

}

}

//OUTPUT Dari JCreator


No comments

Powered by Blogger.