PROGRAM ARRAY
dibuat oleh : Muhammad Rafi - XI RPL 1
SCRIPT ARRAY
1. ARRAY 1 DIMENSI
package array1d;
public class Array1D {
public static void main(String[] args) {
String[] namasiswa = new String[5];
namasiswa[0] = "Muhammad Rafi";
namasiswa[1] = "Yoga Yoga Yoga";
namasiswa[2] = "Jenri Tutorial";
namasiswa[3] = "Furqon Jenong";
namasiswa[4] = "Andre Rehan";
System.out.println(namasiswa[0]);
}
}
2. ARRAY 2 DIMENSI
package array1d;
public class Array1D {
public static void main(String[] args) {
String[] namasiswa = new String[5];
namasiswa[0] = "Muhammad Rafi";
namasiswa[1] = "Yoga Yoga Yoga";
namasiswa[2] = "Jenri Tutorial";
namasiswa[3] = "Furqon Jenong";
namasiswa[4] = "Andre Rehan";
System.out.println(namasiswa[0]);
}
}
2. ARRAY 2 DIMENSI
package array;
public class Array {
public static void
main(String[] args) {
double[]
myList = {1.9, 2.9, 3.4, 3.5};
// mencetak
semua array elemen
for (int i =
0; i < myList.length; i++){
System.out.println(myList[i] + " ");
}
//
Menjumlahkan semua elemen
double total =
0;
for (int i =
0; i < myList.length; i++) {
total +=
myList[i];
}
System.out.println("Total adalah " + total);
// mencari
elemen terbesar
double max =
myList[0];
for (int i =
1; i < myList.length; i++) {
if
(myList[i] > max) max = myList[i];
}
System.out.println("Elemen
terbesar adalah " + max);
}
}
Komentar
Posting Komentar