package modif.array;
public class ModifArray {
public static final int MaxMyArrayLength = 10;
public static int PanjangMyArray = 0;
public static int MyArray[] = new int [MaxMyArrayLength];
public static boolean insertArray (int Data) {
MyArray[PanjangMyArray] = Data;
PanjangMyArray++;
return true;
}
public static void cetakArray () {
if (PanjangMyArray==0) System.out.println("Array Kosong");
else {
System.out.println("Isi dari array : ");
for (int i = 0; i<=PanjangMyArray -1; i++) {
System.out.println(MyArray[i]);
}
}
}
public static boolean Swap(int index1, int index2) {
if ((index1<0) || (index2<0) ||
(index1>PanjangMyArray-1) || (index2>PanjangMyArray-1))
return false;
int temp=MyArray[index1];
MyArray[index1]=MyArray[index2];
MyArray[index2]=temp;
return true;
}
public static void urutgelembung(){
for (int i=0; i<=PanjangMyArray-2; i++)
for (int j=0; j<=PanjangMyArray-2; j++)
if (MyArray[j]<MyArray[j+1]) Swap (j,j+1);
}
public static void main(String[] args) {
insertArray(80);
insertArray(31);
insertArray(60);
insertArray(50);
insertArray(10);
urutgelembung();
cetakArray();
}
}
public class ModifArray {
public static final int MaxMyArrayLength = 10;
public static int PanjangMyArray = 0;
public static int MyArray[] = new int [MaxMyArrayLength];
public static boolean insertArray (int Data) {
MyArray[PanjangMyArray] = Data;
PanjangMyArray++;
return true;
}
public static void cetakArray () {
if (PanjangMyArray==0) System.out.println("Array Kosong");
else {
System.out.println("Isi dari array : ");
for (int i = 0; i<=PanjangMyArray -1; i++) {
System.out.println(MyArray[i]);
}
}
}
public static boolean Swap(int index1, int index2) {
if ((index1<0) || (index2<0) ||
(index1>PanjangMyArray-1) || (index2>PanjangMyArray-1))
return false;
int temp=MyArray[index1];
MyArray[index1]=MyArray[index2];
MyArray[index2]=temp;
return true;
}
public static void urutgelembung(){
for (int i=0; i<=PanjangMyArray-2; i++)
for (int j=0; j<=PanjangMyArray-2; j++)
if (MyArray[j]<MyArray[j+1]) Swap (j,j+1);
}
public static void main(String[] args) {
insertArray(80);
insertArray(31);
insertArray(60);
insertArray(50);
insertArray(10);
urutgelembung();
cetakArray();
}
}
0 komentar:
Post a Comment
Silahkan Tinggalkan Komentar Anda