我无法将小时或天数变为零但是零。我做错了什么? 我需要花几分钟时间和几天。
import java.util.Scanner;
public class NewClass
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int minutes=0,hours=0,days=0, years=0;
System.out.println("Enter the number of mintues");
minutes= input.nextInt();
minutes += (hours*60);
hours += (days*1440);
days += (years*365);
System.out.println("The amount of Hours in minute is: "+hours + "hours");
System.out.println("The amunt of Days is in mintue is: " +days +"days");
}
}
答案 0 :(得分:2)
你的计算错了。您需要以下内容(未经测试):
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int minutes=0,hours=0,days=0, years=0;
System.out.println("Enter the number of mintues");
minutes= input.nextInt();
hours = (minutes/60);
days = (minutes/1440);
System.out.println("The amount of Hours in minute is: "+hours + "hours");
System.out.println("The amunt of Days is in mintue is: " +days +"days");
}
答案 1 :(得分:0)
我认为您使用的是0而不是分钟的值。请参考以下内容:
Scanner input = new Scanner(System.in);
int minutes=0,hours=0,days=0, years=0;
System.out.println("Enter the number of mintues");
//get minute
minutes= input.nextInt();
//calculate hours
hours = minutes / 60;
//calculate days
days = hours/24;
//calculate year
years = days/365;
System.out.println("The amount of Hours in minute is: "+hours + "hours");
System.out.println("The amunt of Days is in mintue is: " +days +"days");
希望得到这个帮助。