询问abaout java Array错误(.class预期)

时间:2019-01-13 10:24:35

标签: java

String huruf;
    String [] kodematkul={"ISMT101","ISIT101","CSMT104","ISIT102","ESQU101","ESQC101"};

String [] matkul= {"Matematika Bisnis","Sistem Informasi dan Tek. Hijau","Komputasi dan Rancangan Berfikir","Algoritma dan Struktur Data","Pendidikan Agama","Pengembangan Managemen Diri"};

int [] nilai={75,80,80,85,70,50};

int [] sks={3,2,4,6,3,2};

    if (nilai[] > 80) {
        huruf = "A";
    }
        else if (nilai[] > 70) {
            huruf ="B";

        }
        else if (nilai[] > 60) {
            huruf = "C";
        }
        else if (nilai[] > 50 ) {
            huruf = "D";
        }
            else {
                huruf ="E";
            }

在是否存在其他情况下,为什么该行出现错误(预期为.class)?谢谢

1 个答案:

答案 0 :(得分:1)

为了获取数组中包含的数据,您将需要提供一个索引值。通常,您将遍历数组,并获得提供索引值的数组元素,例如:

String huruf = "";
for (int i = 0; i < nilai.length; i++) {
    if (nilai[i] > 80) {
        huruf = "A";
    }
    else if (nilai[i] > 70) {
        huruf ="B";

    }
    else if (nilai[i] > 60) {
        huruf = "C";
    }
    else if (nilai[i] > 50 ) {
        huruf = "D";
    }
    else {
        huruf ="E";
    }
}