Java 如何从数组值中获取百分比

Java 如何从数组值中获取百分比,java,arrays,Java,Arrays,我试图从for循环中的数组值中获取一个百分比 System.out.println(playerName[i+1] + " got " + playerScore[i] + " questions right out of " + question.length + "!\n"); double playerScorePercentage = (playerScore[i] / question.length) * 100; System.out.println("Which is

我试图从for循环中的数组值中获取一个百分比

  System.out.println(playerName[i+1] + " got " + playerScore[i] + " questions right out of " + question.length + "!\n");
  double playerScorePercentage = (playerScore[i] / question.length) * 100;
  System.out.println("Which is " + playerScorePercentage + "%!");
我做错了什么?
playerScore
显示一个值,但当我尝试在下面使用它进行计算时,无论发生什么情况,它都显示0.0

运行示例:

John got 3 questions right out of 10!
Which is 0.0%!

尝试在除法之前强制转换值:

double playerScorePercentage = ((double)playerScore[i] / (double)question.length) * 100;
如果你不知道这个主题,可以在网上搜索“整数除法”