【问题标题】:Ask abaout java Array error (.class expected) [duplicate]问 abaout java Array 错误(.class 预期)[重复]
【发布时间】:2019-01-13 10:24:34
【问题描述】:
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";
            }

在 if 和 else if 上,为什么行会出错(预期为 .class)?谢谢

【问题讨论】:

标签: java


【解决方案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";
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多