简体   繁体   English

我怎样才能得到正确的答案显示距离(KM)?

[英]How can I get the correct answer show in distance (KM)?

    Scanner input = new Scanner (System.in);
    
    System.out.print("Enter the TIME in MINUTES: ");
    int minutes = input.nextInt();
    
    input.close();
    
    double hours = (double) (minutes / 60);
    double distance = (double) (50 * hours);
    
    System.out.println("Distance traveled (KM) is " +distance);

Here is my sample program and I need to convert the inputted minutes into hours then convert it into distance traveled, but the output doesn't look like what it is supposed to be.这是我的示例程序,我需要将输入的分钟转换为小时,然后将其转换为行驶的距离,但输出看起来并不像它应该的那样。

Enter the TIME in MINUTES: 45 
Distance traveled (KM) is 0.0
    

I'm really confused and I would definitely be glad if someone would help me.我真的很困惑,如果有人能帮助我,我肯定会很高兴。

Look the below code and find what's wrong in your code.查看下面的代码,找出你的代码有什么问题。

import java.util.Scanner;

public class mainClass {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the TIME in MINUTES: ");
        float minutes = input.nextInt();
        input.close();

        float hours = minutes / 60;
        float distance = 50 * hours;
        System.out.println("Distance traveled (KM) is " +distance);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM