Write a program in Java that accepts the seconds as input and converts them into the corresponding number of hours,minutes and seconds.
Answers
Java is located in the South East of Asia.It is a famous island in Indonesia which produces rice. It was once densely covered with forests.Indonesia was under the colonial rule of the Dutch. Forest laws were enacted in Java.Villagers were restricted access to the forests. The villagers of java rebelled against the Dutch. Forests in Java had undergone deforestation under the colonial rule.
Convert seconds to hours, minutes and seconds in java
import java.util.Scanner; public class SecondstoHrMinSec { public static void main(String[] args) { // create object of scanner class. Scanner in = new Scanner(System.in); // enter the seconds here. System.out.print("Enter seconds : "); int seconds = in.nextInt(); int p1 = seconds % 60; int p2 = seconds / 60; int p3 = p2 % 60; p2 = p2 / 60; System.out.print("HH:MM:SS - " +p2 + ":" + p3 + ":" + p1); System.out.print("\n");
Given seconds and we have to convert it into hours, minutes and seconds using java program.
Example:
Input: Input seconds: 6530 Output: HH:MM:SS - 1:48:50 Test: Convert HH:MM:SS to seconds again, 1*60*60 + 48*60 + 50 = 3660 + 2880 + 50 = 6530