Prime b

Prime b

  • NA
  • 810
  • 346k

Anyone who is good with JAVA help?

Feb 3 2012 6:11 PM
problem: The user enters seconds the output should be days,hours,minutes,seconds format
So if user enter 86400 seconds it will be 1 day, 0 hours, 0 minutes, 0 seconds.
If User enters 86401 seconds it will be 1 days, 0 hours, 0 minutes, 1 second.
Well this is my code, and it doesn't work..

        Scanner scan = new Scanner(System.in);
        double userInput;
        double secondsInDay = 86400;
        double secondsInhours = 3600;
        double secondsInMinutes = 60;
        double seconds;
      
       
       
        System.out.println("Please enter the seconds to convert to days,hours,minutes,seconds");
        userInput = scan.nextDouble();
       
       
        double answerDay = userInput % secondsInDay;
        double answerHours = answerDay % secondsInhours;
        double answerMinutes = answerHours % secondsInMinutes;
        double answerSeconds = answerMinutes;
       
       
       
//         System.out.println(""+answerDay);
//         System.out.println(""+answerHours);
//         System.out.println(""+answerMinutes);
//         System.out.println(""+answerSeconds);
       
         if(answerDay >= 1)
        {
            System.out.println("Days = "+answerDay);
           
        }
         else if(answerDay == 0)
         {
             System.out.println("Zero days");
         }
        
         if(answerHours >= 1)
         {
             System.out.println("Hours = "+answerHours);
         }
         else if(answerHours == 0)
         {
             System.out.println("Zero hours");
         }
        
         if(answerMinutes >= 1)
        {
            System.out.println("Minutes = "+answerMinutes);
        }
         else if(answerMinutes == 0)
         {
             System.out.println("Zero minutes");
         }
        
         if(answerSeconds >= 1)
        {
            System.out.println("Seconds = "+answerSeconds);
        }
         else if(answerSeconds == 0)
         {
             System.out.println("Zero seconds");
         }


Answers (8)