분류 전체보기502 [Java] chap12: 기본 API - 기본 API Exam3. 📌 package chap12; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Scanner; /* * 년도와 월을 입력받아 해당월의 마지막일자와 요일을 출력하기 * Calendar 클래스 이용 */ public class Exam3 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("년도와 월을 입력하세요."); int year = scan.nextInt(); int mon = scan.nextInt(); Calendar cal = Calendar.getInstance(); cal.. 2023. 4. 16. [Java] chap12: 기본 API - Calendar Calendar 클래스 Calendar 클래스 추상클래스임. 1. 추상메서드를 멤버로 가질수있다. 2. 객체화 불가. new Calendar() 오류. => 상속을 통해서 자손클래스의 객체화를 통해 객체화 가능. 3. abstract 예약어로 구현함. getInstance() static 메서드를 통해서 객체 전달 📌 package chap12; import java.util.Calendar; public class CalendarEx1 { public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now); //get(상수값) : 지정된 상수값에 맞는 값을 리턴 System.out.pr.. 2023. 4. 16. [Java] chap12: 기본 API - 기본 API Exam2.(Date) 📌 package chap12; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; /* * 년도와 월을 입력받아 해당월의 마지막일자와 요일을 출력하기 */ public class Exam2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("년도와 월을 입력하세요."); int year = scan.nextInt(); int mon = scan.nextInt(); //System.out.println(year+"-"+m.. 2023. 4. 16. [Java] chap12: 기본 API - Date, getTime() Date 클래스 Date 클래스 : 날짜 표현하는 클래스. 현재일시객체 생성 SimpleDateFormat 클래스 : Date 객체를 형식화된 문자열로 변경 String format(Date객체) : Date객체를 형식화된 문자열로 리턴 Date parse(형식화된문자열객체) : 형식화된 문자열객체를 Date로 리턴 parseException 예외처리 필수 날짜 format에 사용되는 문자 yyyy : 년도 4자리 MM : 월을 2자리 dd : 일을 2자리 HH : 시간을 2자리 mm : 분을 2자리 ss : 초를 2자리 E : 요일 a : 오전/오후 📌 package chap12; import java.text.ParseException; import java.text.SimpleDateFormat; .. 2023. 4. 16. [Java] chap12: 기본 API - 기본 API Exam1 📌 package chap12; import java.util.Random; /* * Random 클래스의 nextBoolean 함수를 이용하여 사용자1,사용자2의 난수를 발생하여 * 3번 연속으로 true가 먼저 나오는 쪽이 승리하도록 프로그램 구현하기 */ public class Exam1 { public static void main(String[] args) { Random rand1 = new Random(); rand1.setSeed(System.currentTimeMillis()); Random rand2 = new Random(); rand2.setSeed(System.currentTimeMillis()+100); int user1=0,user2=0; while(true) { if(rand.. 2023. 4. 16. [Java] chap12: 기본 API - Random Random 클래스 Random 클래스 : 난수 발생을 위한 클래스 1. 자료형별로 난수 발생을 위한 메서드 존재. nextInt() : 정수형 난수 리턴 nextInt(n) : 0 2023. 4. 16. [Java] chap11: 기본 API(패키지 클래스) - 기본 API Exam 4-5 (format 메서드, 함수 구현) 📌 기본 API Exam4. (format 메서드) package chap11; /* * format 메서드 구현하기 * 메서드명 : String format (String str,int len,int align) * 기능 : 주어진 문자열을 지정된 크기(len)의 문자열로 변환. * 나머지 공간은 공백으로채운다. * (0 : 왼쪽 정렬, 1: 가운데 정렬, 2:오른쪽 정렬) */ public class Exam4 { public static void main(String[] args) { String str = "가나다"; System.out.println(format(str, 7, 0));//가나다 System.out.println(format(str, 7, 1));// 가나다 System.out.p.. 2023. 4. 16. [Java] chap11: 기본 API(패키지 클래스) - Wrapper Wrapper 클래스 Wrapper 클래스 : 8개의 기본자료형을 객채화 하기 위한 8개의 클래스 통칭 기본자료형 - 정수이므로 값만 가지고 있다. Wrapper 클래스 boolean Boolean char Character byte Byte short Short int Integer long Long float Float double Double 기본자료형과 참조자료형 사이의 형변환은 불가.(함수를 이용하여 처리) 단 기본자료형과 Wrapper 클래스 간의 형변환은 가능함. 기본자료형의 기본형(변수) 2023. 4. 16. 이전 1 ··· 47 48 49 50 51 52 53 ··· 63 다음