public class Time
{
public static void main(String[] args) {
int hour, minute,second;
hour=13;
minute=46;
second=45;
int total_sec1=(hour*3600)+(60*minute)+second;
int sec_since_midnight=(second + (minute*60) + (hour*3600));
System.out.println("Number of seconds since midnight: "+sec_since_midnight);
int sec_end_day=(60-second) + ((60-1-minute)*60) + (24-1-hour)*3600;
System.out.println("Number of seconds remaining in the day: "+sec_end_day);
float total=sec_since_midnight+sec_end_day;
float perc_day_passed=(sec_since_midnight/total)*100;
System.out.println("Percentage of the day that has passed: "+perc_day_passed);
hour=14;
minute=46;
second=45;
int total_sec2=(hour*3600)+(60*minute)+second;
int sec_elapsed=total_sec2-total_sec1;
System.out.println("Elapsed time: "+sec_elapsed+" seconds");
}
}
Comments
Leave a comment