W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
public class Main {
  public static void main(String[] args) {
    // 设置游戏最高分为 500
    int maxScore = 500;
​
    // 用户实际得分
    int userScore = 423;
​
    /* 计算用户得分占最高分的百分比。
    将 userScore 转为 float 类型以确保除法运算的精确性 */
    float percentage = (float) userScore / maxScore * 100.0f;
​
    // 打印结果
    System.out.println("用户得分百分比是 " + percentage);
  }
}