현재 시간을 보여주는 시계를 자바로 만들었습니다. 시계가 모두 1 분 간격으로 업데이트되었는지 확인하여 콘솔에서 결과를 업데이트합니다. 스레드를 사용하기 위해 책을 읽었지만 주제에 대해 잘 알지 못합니다. 누가 도와 주겠습니까?
import java.util.*;
public class Current
{
public static void main(String[] args)
{
Calendar calendar = new GregorianCalendar();
String hour;
int time = calendar.get(Calendar.HOUR);
int m = calendar.get(Calendar.MINUTE);
int sec = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
hour = "A.M.";
else
hour = "P.M.";
System.out.println(time + ":" + m + ":" + sec + " " + hour);
}
}
class Data
{
public static void main(String[] args)
{
Calendar cal = new GregorianCalendar();
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
System.out.println(day + "-" + (month + 1) + "-" + year);
}
}
public static void main(String[] args) {
while (true) {
try {
Thread.sleep(60*1000); //one minute
Calendar calendar = new GregorianCalendar();
String hour;
int time = calendar.get(Calendar.HOUR);
int m = calendar.get(Calendar.MINUTE);
int sec = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
hour = "A.M.";
else
hour = "P.M.";
System.out.println(time + ":" + m + ":" + sec + " " + hour);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다