본문 바로가기

자바의 정석-기초편9

Chapter06. 객체지향 프로그래밍I(1) 6-1) public class student { String name; int ban; int no; int kor; int eng; int math; } 6-2) public class Exercise6_2 { public static void main(String[] args) { Student s = new Student("홍길동", 1, 1, 100, 60, 76); String str = s.info(); System.out.println(str); } } class Student{ String name; int ban; int no; int kor; int eng; int math; public Student(String name, int ban, int no, int kor, int eng.. 2023. 6. 25.
Chapter 5. 배열 연습문제 5-1 (1) int[] arr[]; // 2차원 배열 선언 잘 선언함 (2) int[] arr={1,2,3,}; //마지막 쉼표는 있어도 상관없음 (3) int[] arr=new int[5]; // 잘 선언함 (4) int[] arr=new int[5]{1,2,3,4,5}; // 틀림, 크기 지정하면 안됨 괄호 안의 데이터 개수에 따라 자동결정 (5) int arr[5]; // 틀림, 배열 선언에 크기를 넣으면 안됨 생성해줘야함 (6) int arr[] arr[] = new int[3][]; // 가변배열, 다차원 배열을 생성할 때 마지막 차수의 길이를 지정하지 않으면, 고정된 // 형태가 아닌 보다 유동적인 가변 배열을 구성 할 수 있음 5-2 arr[3].length -> 2 5-3 for(int .. 2023. 3. 3.
Chapter 4. 조건문과 반복문 연습문제 4-1 (1) 10 2023. 2. 21.
Chapter 3. 연산자 연습문제 3-1 byte b=10; char ch='A'; int i=100; long l=1000L; (1) b=(byte)i; // int->byte 형변환 필요 (2) ch=(char)b; // char(2byte) > byte(1byte)지만 범위가 달라서 형변환 필요 (3) short s=(short)ch; // short(2byte), char(2byte)지만 범위가 달라서 형변환 필요 (4) float f=(float)l; // float(4byte) long(8byte) float범위가 더 큼 형변환 생략 가능 (5) i=(int)ch; // int(4byte) > char(2byte) 형변환 생략 가능 3-2 True 13 5 False 2 66 B B // println은 값을 타입에따라 어떻게.. 2023. 2. 14.