Sunday, June 30, 2019

Convert Seconds into days, hours, minutes and seconds in Java


Write a program that will ask the user to give a number in the integer (seconds) and convert it into days, hours, minutes and seconds and display it on the screen.

If you like my work please click the ads on my website to support my work. I will really appreciate your help. 

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com


Program Listing

package seconds;

import java.util.Scanner;
/**
 * Seconds.java
 * @author Jake Rodriguez Pomperada,MAED-IT
 * February 18, 2019  Sunday
 * http://www.jakerpomperada.com
 * jakerpomperada@gmail.com 
 * Bacolod City, Negros Occidental
 */
public class Seconds {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int n=0;
        System.out.println();
        System.out.print("\tConvert Seconds into days, hours, minutes and seconds");
        System.out.println("\n");
        System.out.print("\tGive Value in Seconds : ");
        n=input.nextInt();
        int day = n / (24 * 3600); 
        n = n % (24 * 3600); 
        int hour = n / 3600; 
        n %= 3600; 
        int minutes = n / 60 ; 
        n %= 60; 
        int seconds = n; 
        System.out.println();
        System.out.println("\tIt will be " +day + " " + "day(s) " + hour  
                           + " " + "hour(s) " + minutes + " "
                           + "minute(s) " + seconds + " "
                           + "seconds."); 
        System.out.println();
        System.out.print("\tEnd of Program");
        System.out.println("\n");
    }
}

No comments:

Post a Comment