java seconds program?

hi could somebody please help me with this

a program to prompt the user for a positive integer number of seconds and output the number of hours, minutes and seconds that it represents. (in Java)

and as simple as possible please the coding..

many thanks..

Update:

ok thanks for this i kind of get it now but my one question is

what are the calculations to show expected results for 3793 seconds = hours 1 , minuets 3, seconds 13

is this right?

and how do i do an analysis of this

Comments

  • Let's see an attempt at solving the problem and then we'll help you. Google "Java tutorials". Look at numbers and operators.

    Edit:

    That's better. Let's see.

    user enters 7680 secs.

    (1 hr / 3600 secs) * (7680 secs) = 2 hrs

    7680 - (3600 * 2) = 480 secs leftover

    To get the leftover you could also do 7680%3600 = 480

    (1 min / 60 secs) * (480 secs) = 8 mins

    /////////////////////////////

    int usr = 7685

    int hrs = usr/3600;

    int min = (usr%3600)/60;

    int secs = (user%3600)%60

    //////////////////////////////

    Welcome to the modulus operator. It's used to get the leftovers. Learn it. It's used extensively.

  • import java.util.Scanner;

    public class Seconds {

    public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.print("Input number of seconds: ");

    int seconds = scanner.nextInt();

    int hours = seconds / 3600;

    seconds = seconds % 3600;

    int minutes = seconds / 60;

    seconds = seconds % 60;

    System.out.println("hours = "+hours);

    System.out.println("minutes = "+minutes);

    System.out.println("seconds = "+seconds);

    }

    }

  • Go to clearsidetechnologies.com

    They can help you with programming.

Sign In or Register to comment.