gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:33:17 25 4
gpt4 key购买 nike

这句话有什么问题吗?它总是输出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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com