Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Output Time from a Whole Number Input

$
0
0
I need help writing a Java program that takes as input a length of time measured in seconds. The program then outputs the same length as the corresponding number of hours, minutes, and seconds. For instance, if the user enters “7350”, the program should output “2 hours, 2 minutes, and 30 seconds”.

What I know so far is that I have to divide the input by 3660 to get the hours and divide by 60 to get the minutes. For the minutes and secods, I've run into the problem of finding out the exact minute if it is less than 59.at I

This is what I have so far:
import java.util.Scanner;
import java.text.*;

public class Question2{
  public static void main (String[] args){
    
    Scanner userInput = new Scanner(System.in);
    DecimalFormat twoPlaces = new DecimalFormat("#");
    
    double secondsInput, seconds, minutes, hours;
    
    System.out.println("Welcome to The Super Time Calculator");
    System.out.print("Please enter how many seconds you would like outputted in time: ");
    secondsInput = userInput.nextDouble();
    
    hours = secondsInput/3600;
    minutes = secondsInput/60;
  }
}


Any ideas?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>