Programming Examples

Java program to input the time in hours minutes and seconds and print it in seconds


Write a program to input the time in hours, minutes and seconds and print it in seconds.

For Example:

INPUT: Enter time in hours:

1

Enter time in minutes:

12

Enter time in seconds:

6

OUTPUT:

Time in seconds:4326

Solution

import java.util.*;
class Q16
{
	public static void main(String arr[])
	{
		Scanner sc=new Scanner(System.in);
		int h,m,s,sec;
		System.out.println( “Enter time in hours:”);
		h=sc.nextInt();
		System.out.println( “Enter time in minutes:”);
		m=sc.nextInt();
		System.out.println( “Enter time in seconds:”);
		s=sc.nextInt();
		sec=h*3600+m*60+s;
		System.out.println( “Time in seconds:”+sec);
	}
}
Output

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz