Write an application that reads values representing a time d

Write an application that reads values representing a time duration in hours, minutes, and seconds and then prints the equalivant total number of seconds. (for example, 1 hour, 28 minutes and 42 seconds is equivalent to 5322 seconds.)

Solution

An application that reads values representing a time duration in hours, minutes, and seconds and then prints the equalivant total number of seconds :-

import java.io.*;

class Application

{

public static void main(String[ ] args) throws IOException

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(\" Enter a time duration in hours:\");

int a = Integer.parseInt(br.readLine()); // reading hours from keyboard

a = a*60*60; // converting hours into seconds

System.out.print(\" Enter a time duration in minutes:\");

int b = Integer.parseInt(br.readLine()); // reading minutes from keyboard

b = b*60; // converting minutes into seconds

System.out.print(\" Enter a time duration in seconds:\");

int c = Integer.parseInt(br.readLine()); // reading seconds from keyboard

int result = a+b+c; // adding a&b&c

System.out.println(\" Equalivant total number of seconds: =\"+result); // displays the result

}

}

OUTPUT :-

Enter a time duration in hours: 1

Enter a time duration in minutes: 28

Enter a time duration in seconds: 42

Equalivant total number of seconds: = 5322

Write an application that reads values representing a time duration in hours, minutes, and seconds and then prints the equalivant total number of seconds. (for

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site