CODING ARRAY JAVA

0 comments

ne buat sobat-sobat yg mw buat array java ane kasi source codenya

public class aray
{
public static void main(String[] args)
{
int[]data=new int [5];//deklarasi array

System.out.println("jumlah elemen data: "+data.length);//hitung panjang elemen
System.out.println("\nData awal");
System.out.println("--------------");

for(int i=0;i<data.length;i++)
{
data[i]=67;//isi nilai di setiap elemen aray

//mengambil nilai array dari elemen
System.out.println("isi data["+i+"]"+ " ==> "+data[i]);
}

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

System.out.println("\nData akhir");
System.out.println("--------------");

for(int i=0;i<data.length;i++)
{
//mengubah nilai elemen array
data[i] = (int) (Math.random()*100);
System.out.println("isi data["+i+"]"+ " ==> "+data[i]);
}

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


// proses awal sorting
for (int kiri=0;kiri<data.length-1;kiri++)
{
for (int kanan=kiri+1;kanan<data.length;kanan++)
{
if (data[kiri] < data[kanan])
{
int bantu = data[kiri];
data[kiri] = data[kanan];
data[kanan] = bantu;
}
}
}
// proses akhir sorting

System.out.println("\nData sortir");
System.out.println("--------------");

for(int i=0;i<data.length;i++)
{
//mengubah nilai elemen array
System.out.println("isi data["+i+"]"+ " ==> "+data[i]);
}

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

}
}

semoga bermanfaat :)

No comments:

Post a Comment

×
 
SANG-ILMU © 2011 sang-ilmu.blogspot.com. Supported by Mustafa and Tiwi