목록JAVA/chapter20_api (13)
WON.dev
Q1. Test01.java Score 클래스 필드 : int kor, eng, mat 메소드 : Constructor, toString(), equals() Score 인스턴스를 2개 생성하고, 동등 비교(세과목이 모두 같으면 동등) 결과 출력 각 인스턴스 정보는 toString 메소드를 통해 출력 Q2. Test02.java User 클래스 필드 : String id, password 메소드 : Constructor, toString(), equals() User 인스턴스를 2개 생성하고, 동등 비교(id, password 모두 같으면 동등) 결과 출력 각 인스턴스 정보는 toString 메소드를 통해 출력 Q3. Test03. java Coordinate 클래스필드 : int x, int y; 메소..
package org.joonzis.ex; import java.util.Calendar; public class Ex12_Dday { public static void main(String[] args) { Calendar date1 = Calendar.getInstance();// 기념일 Calendar date2 = Calendar.getInstance();// 현재 날짜 // 기념일로 수정 date1.set(2023, Calendar.AUGUST, 12); // 밀리 초 단위로 계산하려면 long을 쓰자. long milSec = date2.getTimeInMillis() - date1.getTimeInMillis(); // 1000 밀리초 = 1초, 60초 = 1분, 60분 = 1시간, 24시간..
package org.joonzis.ex; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Ex11_Calendar_Date { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // Calendar 객체를 이용하여 현재 날짜 가져오기(Date 객체 생성) Date now = cal.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("a hh시 mm분 ss초"); String today = sdf.format(now); System.out...
package org.joonzis.ex; import java.text.SimpleDateFormat; import java.util.Date; public class Ex10_Date_SimpleDateFormat { public static void main(String[] args) { Date now = new Date();// Date와 SimpleDateFormat은 짝꿍으로 쓰자 System.out.println(now); // SimpleDateFormat // 년 : yy, yyyy // 월 : M, MM // 일 : d, dd // 요일 : E // 오전오후 : a // 시 : hh(12시각제), HH(24시각제) // 분 : mm // 초 : ss SimpleDateFormat fo..
package org.joonzis.ex; import java.util.Calendar; public class Ex09_Calendar { public static void main(String[] args) { // Calendar는 추상 클래스라서 객체를 생성할 수 없다. // Calendar 클래스를 구현한 클래스의 getInstanse()를 사용하여 반환 Calendar cal = Calendar.getInstance();// 현재 시간으로 자동 세팅 // 특정 날짜 셋팅 //cal.set(1980, 9, 21, 11, 34, 10); System.out.println("년 : " + cal.get(Calendar.YEAR)); // 월 : 0 ~ 11 이므로 +1을 하자 System.out...
package org.joonzis.ex; import java.math.BigDecimal; import java.math.BigInteger; public class Ex08_Big_number { public static void main(String[] args) { // int형 최대 값 System.out.println(Integer.MAX_VALUE); // long형 최대 값 System.out.println(Long.MAX_VALUE); // BigInteger 클래스를 활용해서 long 타입 이상/이하 사용 가능 // 반드시 문자열 처리해서 적어주자 BigInteger a = new BigInteger("12345678901234567890"); BigInteger b = new Big..
package org.joonzis.ex; /* * Wrapper Class * 1. primitiveType -> referenceType 변경해주는 클래스 * 2. 종류 * 1) int-> Integer * 2) double-> Double * 3) boolean-> Boolean * 4) char-> Character * 3. 변수를 "객체"로 변환해주는 클래스 * 4. 반드시 referenceType을 사용해야 하는 경우에 사용 */ public class Ex07_Wrapper { public static void main(String[] args) { Integer a = new Integer(10);// 10을 저장한 객체(인스턴스) a Integer b = new Integer(10); /..
package org.joonzis.ex; public class Ex06_StringBuffer {// StringBuffer나 StringBuilder나 똑같음 public static void main(String[] args) { StringBuffer sb1 = new StringBuffer("apple"); StringBuffer sb2 = new StringBuffer("apple"); System.out.println("sb1 해시코드값(주소값) = " + sb1.hashCode()); System.out.println("sb2 해시코드값(주소값) = " + sb2.hashCode()); // 검색 : 해시코드 비교 -> (같은 해시코드만 ) 동등 비교 StringBuffer sb = ne..
package org.joonzis.ex; public class Ex05_String { public static void main(String[] args) { // 인스턴스는 다르지만 내부 데이터가 동일하므로 객체 1개만 저장 String a = "apple"; String b = "apple"; System.out.println(a == b ? "apple 1개" : "apple 2개"); String c = new String("banana"); String d = new String("banana"); System.out.println(c == d ? "banana 1개" : "banana 2개"); // .split() String sn = "000000-1234567"; String[] s..