【问题标题】:Computing Letter Grade and Adding it to a One-Dim arrary计算字母等级并将其添加到一维数组
【发布时间】:2017-08-01 07:28:56
【问题描述】:

在这部分编程中,我尝试将字母等级分配给数字等级。我在使用 if 语句之前已经这样做了,但这次我试图将它分配到一个数组序列中。该数组的类型为 char。 score[] 包含数字等级。我不确定如何将字母分配给数组。我确定这是一个我没有想到的简单修复。如果您有任何帮助,将不胜感激。谢谢

(score[i] 已经用另一种方法确定,我知道它可以工作,因为它会在我的输出语句中打印它们,而我的计算平均方法,只是不想复制整个代码)

public void computeGrades (){
    if (scores[i] >= 90){
        grades[] = 'A';
    }
    else if (scores[i] >= 80){

    }
    else if (scores[i] >= 80){

    }
    else if (scores[i] >= 70){

    }
    else if (scores[i] <= 60){

    }

}

【问题讨论】:

    标签: arrays if-statement char int assign


    【解决方案1】:

    在您的第一个if 语句中,您尝试将字符'A' 分配给一个数组。相反,您应该将 char 分配给数组中的特定元素:

    grades[i] = 'A';
    

    您将在其他情况下遵循此模式。

    if (scores[i] >= 90){
        grades[i] = 'A';
    }
    else if (scores[i] >= 80){
        grades[i] = 'B'; //I assume 'B' here
    }
    

    等等。

    一个问题,你从哪里得到i 的值?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多