Input a time from the keyboard and output its next second

The code is as follows:

import java. util. Scanner; Class demo9 {public static void main (string [] args) {scanner SC = new scanner (system. In); system.out.println ("please enter a time in HH mm SS format"); int hour = sc.nextint(); int minute = sc.nextint(); int second = sc.nextint(); system.out.println ("the current time is:" + hour + ":" + minute + ":" + second); / / calculate the next second + +; / / correct the time if (second>=60){ second=0; minute++; if(minute>=60){ minute=0; hour++; if(hour>=24){ hour=0; } } } // Output system out. Println ("the next second is:" + hour + ":" + minute + ":" + second);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>