I can't get the hours or day into a number but Zero. What I am i doing wrong?
I need to get minutes into hours and days.
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");
}
}
Your calculation is wrong. You need something like below(untested):
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");
}
I think you used the 0 instead of the value of minute. Please refer below:
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");
Hope this help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.