【问题标题】:Calculate the percentage between 2 arrays and output a new array计算2个数组之间的百分比并输出一个新数组
【发布时间】:2013-04-06 13:10:51
【问题描述】:

对你们大多数人来说,这很简单,但我是新手——所以不要太讨厌!好的,所以我有两个数组,一个显示“正确分数”,另一个显示“错误分数”。我想使用这些显示正确百分比的新数组。

我写过:

int[] correct1 = {20, 20, 13, 15, 22, 18, 19, 21, 23, 25};
int[] incorrect1 = {2, 1, 5, 2, 2, 5, 8, 1, 0, 0, 1};

for(int a = 0; a < correct1.length; a++ ){ 
        int[] percentage1 = ((correct1[a] / (correct1[a] + incorrect1[a]))*100);
    }

但这给了我 int 和 int[] 之间的类型不匹配。任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: java arrays percentage


    【解决方案1】:
    for(int a = 0; a < correct1.length; a++ ){ 
            int[] percentage1 = ((correct1[a] / (correct1[a] + incorrect1[a]))*100);
        }
    

    上面应该是:

    double[] percentage1 = new double[correct1.length];
    for(int a = 0; a < correct1.length; a++ ){ 
        percentage1[a] = (double)((correct1[a] / (correct1[a] + incorrect1[a]))*100);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 2018-07-27
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多