Menu Close

Units of Time days,hours,min to seconds in Java …ftc

Create a program that reads a duration from the user as a number of days, hours, minutes, and seconds. Compute and display the total number of seconds represented by this duration.

Input:
Days: 20       
Hours: 12
Minutes: 50
Seconds: 10

The Total Seconds for 20 days 12 hours 50 minutes 
10 seconds is 1774210 seconds.
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    System.out.print("No: of Days:  ");
    int days = s.nextInt();
    System.out.print("No: of Hours:  ");
    int hours = s.nextInt();
    System.out.print("No: of Minutes:  ");
    int min = s.nextInt();
    System.out.print("No: of Seconds:  ");
    int sec = s.nextInt();

    int total_seconds = sec;
    total_seconds += min*60;
    total_seconds += hours*3600;
    total_seconds += days*24*3600;

    System.out.println("The Total Seconds for "+days+" days "+hours+" hours "
    +min+" minutes "+sec+" seconds is "+total_seconds);

    	}
}

INPUT_1:
No: of Days:  6
No: of Hours:  12
No: of Minutes:  34
No: of Seconds:  45

OUTPUT:
The Total Seconds for 6 days 12 hours 34 minutes 45 seconds is  563685 seconds.


INPUT_2:
No: of Days:  9
No: of Hours:  20
No: of Minutes:  23
No: of Seconds:  25

OUTPUT:
The Total Seconds for 9 days 20 hours 23 minutes 25 seconds is  851005 seconds.


INPUT_3:
No: of Days:  20
No: of Hours:  12
No: of Minutes:  50
No: of Seconds:  10

OUTPUT:
The Total Seconds for 20 days 12 hours 50 minutes 10 seconds is  1774210 seconds.


INPUT_4:
No: of Days:  50
No: of Hours:  20
No: of Minutes:  60
No: of Seconds:  60

OUTPUT:
The Total Seconds for 50 days 20 hours 60 minutes 60 seconds is  4395660 seconds.


ILLUSTRATION

Executed using javac in linux terminal

Leave a Reply

Your email address will not be published. Required fields are marked *