From e188aedc25f1331befbd22e04fe24aae75c3e922 Mon Sep 17 00:00:00 2001 From: kieran Date: Mon, 29 Jan 2024 12:45:33 -0800 Subject: [PATCH] Java2 --- src/Time.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Time.java diff --git a/src/Time.java b/src/Time.java new file mode 100644 index 0000000..b4782ef --- /dev/null +++ b/src/Time.java @@ -0,0 +1,32 @@ +import java.time.LocalTime; + +public class Time { + + public static void main(String[] args) { + + int hour = 13; + int minute = 43; + int second = 45; + + int secondsSinceMidnight = hour * 3600 + minute * 60 + second; + + int secondsInADay = 24 * 3600; + int secondsRemaining = secondsInADay - secondsSinceMidnight; + + double percentagePassed = (double) secondsSinceMidnight / secondsInADay * 100; + + System.out.println("Number of seconds since midnight: " + secondsSinceMidnight); + System.out.println("Number of seconds remaining in the day: " + secondsRemaining); + System.out.printf("Percentage of the day that has passed: %.2f%%\n", percentagePassed); + + LocalTime currentTime = LocalTime.now(); + hour = currentTime.getHour(); + minute = currentTime.getMinute(); + second = currentTime.getSecond(); + + int elapsedSeconds = hour * 3600 + minute + second - secondsSinceMidnight; + + System.out.println("\nElapsed time since starting the exercise: " + elapsedSeconds + " seconds"); + + } +}