Results 1 to 4 of 4
  1. #1
    mrnoahf is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default im very new to java need help with taking years and turning it into days, hours, etc.

    I need to turn a number of years into days hours minutes and seconds but if i put in one year then it shows up as 0 days 0 hours 0 minutes and 0 seconds
    this is for a class

    this is my code:
    package classwork;

    import java.util.*;
    public class Yearsdivided {

    final static int DAYS = 365;
    final static int HOURS = 24;
    final static int MINUTES = 60;
    final static int SECONDS = 60;
    static Scanner console = new Scanner(System.in);

    public static void main(String[] args) {

    int years;

    System.out.println("Please enter an amount of years then press enter");
    years = console.nextInt();

    System.out.println("The amount of years you entered is: " + years);

    System.out.println("The amount of days are: " + ( years / DAYS));

    years = years % DAYS;

    System.out.println("The amount of hours are: " + (years / HOURS));

    years = years % HOURS;

    System.out.println("The amount of minutes are: " + (years / MINUTES));

    years = years % MINUTES;

    System.out.println("The amount of seconds are: " + (years / SECONDS));

    and this is what i get as output:

    Please enter an amount of years then press enter
    1
    The amount of years you entered is: 1
    The amount of days are: 0
    The amount of hours are: 0
    The amount of minutes are: 0
    The amount of seconds are: 0

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You've got basic math errors here. Figure out the math with paper and a calculator and then translating it to Java will be easy.

  3. #3
    mrnoahf is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    thanks i think i got it

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. How many years have you been using Java?
    By derrickD in forum Jobs Discussion
    Replies: 41
    Last Post: 05-06-2011, 07:15 AM
  2. I want to fetch last 7 days records in java
    By rasikow in forum New To Java
    Replies: 3
    Last Post: 12-05-2008, 12:34 PM
  3. Simple Project 4 or 5 Hours Pay $100
    By billaaa777 in forum Jobs Offered
    Replies: 0
    Last Post: 08-30-2008, 12:45 AM
  4. Replies: 0
    Last Post: 05-18-2008, 09:31 AM
  5. Taking Java In School Need Help
    By xEuPhOrIcSx in forum New To Java
    Replies: 7
    Last Post: 02-04-2008, 08:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •