본문 바로가기

반응형

DEMO CODE

(28)
[JAVA] Ex004 어제, 내일 날짜 구하기 소스 import java.util.*;public class CalendarAfAndBfMain{public static void main(String[] args) {CalendarAfAndBf cal=new CalendarAfAndBf();//setDate의 주석을 풀자Date d=cal.setDate(2013, 8,31);System.out.println("기준날 :"+d.toString());System.out.println("다음날 :"+cal.afterOneDay(d));System.out.println("기준날 :"+cal.beforOneDay(d));}} class CalendarAfAndBf {/** * 입력한 다음날을 구한다. * @param d 입력 다음 날을 출력하기 위한 입력 날 * ..
[JAVA] Ex003 솟수 판단 소스 public class HelloCommentMain {public static void main(String[] args) {HelloComment hc = new HelloComment();System.out.printf("2343251은 솟수일까? %b%n", hc.isPri(2343251));}}class HelloComment {public boolean isPri(int a) {boolean isP = true;int b = (int) Math.sqrt(a);for (int i = 2; i
[JAVA] Ex002 윤년출력 및 판단 소스 public class IfLeapYear {public static void main(String[] args) {for (int year = 1998; year < 2020; year++) {boolean yearTF = false;if ((0 == (year % 4) && 0 != (year % 100)) || 0 == year % 400) {yearTF = true;} else {yearTF = false;} if (yearTF) {// System.out.println(year+"는 윤년입니다. ");System.out.printf("%d는 윤년입니다.%n", year);} else {// System.out.println(year+"는 윤년이 아닙니다.");System.out.printf("%..
[JAVA] Ex001 윤년판단 소스 public class HelloCalendar {//윤년인가? non staticpublic boolean isLeapYear(int year){boolean yearTF=false;if( ((year % 4==0) && (year %100 !=0)) || year%400==0 ){yearTF = true;}return yearTF;}//윤년인가? staticpublic static boolean isLeapSY(int year){boolean yearTF=false;if( ((year % 4==0) && (year %100 !=0)) || year%400==0 ){yearTF = true;}return yearTF;}public static void main(String[] args) {HelloCa..

반응형