java - 无论 num1、num2 或 num3 输入什么,总分始终等于 0.0

标签 java java.util.scanner

这句话有什么问题吗?它总是输出0.0而不是总分结果

import java.util.Scanner;

public class d {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int num1;
        int num2;
        int num3;
        int percentnum1;
        int percentnum2;
        int percentnum3;
        double totalscore;

        System.out.print("Enter paper 1 score (out of 90): ");
        num1 = input.nextInt();

        System.out.print("Enter paper 2 score (out of 90): ");
        num2 = input.nextInt();

        System.out.print("Enter IA score (out of 20): ");
        num3 = input.nextInt();

        percentnum1 = (num1 / 90) * 100;
        percentnum2 = (num2 / 90) * 100;
        percentnum3 = (num3 / 20) * 80;

        totalscore = (percentnum1 * 0.4) + (percentnum2 * 0.4) + (percentnum3 * 0.2);

        System.out.println("The total score is " + totalscore);


    }
}

最佳答案

int更改为doubleto avoid rounding down to 0 .

关于java - 无论 num1、num2 或 num3 输入什么,总分始终等于 0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43554937/

相关文章:

Java:打印数组中数字的位置

java - 如何在 Java 中使用 Scanner、while 和 for 循环来递增字符串名称

java - Java中非常简单的用户登录系统

java - getBundle 找不到属性文件

java - 用iBatis映射父子关系

java - 使用递归求数组的最小值?

java - Java/Groovy 中是否有可用的临时报告生成器库?根据选择的维度/度量生成 SQL 查询

java - ClassNotFoundException : org. springframework.web.context.ContextLoaderListener 问题

java - 如何从文本文件获取数据并将其保存到字符串中?

java.util.InputMismatchException 使用scanner.nextFloat JAVA