Mengakses Elemen Aray
Mengakses Elemen Aray. public class array { public static void main (String args[]) { int nilai []=new int[3]; nilai[0]=70; nilai[1]=80; nilai[2]=65; double ratarata=0.0; for (int i=0; i<nilai.length; i++) ratarata+=nilai[i]; ratarata/=nilai.length; System.out.println("Nilai rata-rata = " + ratarata); } } import java.text.NumberFormat; public class array2 { public static void main(String args[]) { NumberFormat nf=NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); int nilai[][]=new int[2][3]; nilai[0][0]=85; nilai[0][1]=81; nilai[0][2]=78; nilai[1][0]=65; nilai[1][1]=73; nilai[1][2]=71; String MK[]={"RPL", "PBO"}; double ratarataMK[]=new double[nilai.length]; for (int i=0; i<nilai.length; i++) { for (int j=0; j<nilai[0].length; j++) { ratarataMK[i]+=nilai[i][j]; } ratarataMK[i]/=nilai[0].length; } System.out.println("Nilai Mata Kuliah\n"); System.out.println("MK\tMinggu\tM