목록JAVA (194)
WON.dev
Q1. 클래스 Car 를 정의하시오. - 필드 : String model,String color, int year - 메소드 : setFields(model, color) : 올해를 year로 처리, setFields(model, color, year), output() 클래스 CarMain을 정의 하시오. ★ Calendar calendar = Calendar.getInstance(); calendar.get(Calendar.YEAR); // 현재 년도 Q2. 클래스 Dog을 정의하시오. - 필드 : String name, String breed, int age - 메소드 : setDog(name, age) : 품종은 푸들 setDog(name, age, breed) info() - name, age,..
package org.joonzis.ex; public class Test_Oper { // 필드 double val1, val2; // 두 값을 이용하여 사칙연산을 하는 클래스 // 1. 두 값을 전달 받아 두 값의 합을 출력하는 plus 메소드 void plus(double num1, double num2){ System.out.println(num1 + num2); } // 2. 전역 변수 두 개의 차를 출력하는 minus 메소드 void minus() { System.out.println(val1 - val2); } // 3. 전역 변수 두 개의 곱을 출력하는 multi 메소드 void multi() { System.out.println(val1 * val2); } // 4. 전역 변수 두 개의 ..
package org.joonzis.ex; public class Ex04_Triangle { int width; int height; void setFields(int w, int h) { width = w; height = h; } // 아래 두 calcArea 메소드가 오버로딩 되지 않은 이유 // -> 메소드 이름은 같으나, 매개변수가 다르지 않다. int calcArea() {// 일부러 오류 냄 return width * height / 2; } double calcArea() { return width * height / 2.0; } }
package org.joonzis.ex; public class Ex03_RecursiveClass { static int count = 0; static void recursive() { System.out.println("recursive() call"); count++; if(count == 5) { return;// recursive() 메소드 종료 } recursive();// 재귀 호출 } public static void main(String[] args) { recursive(); } }
package org.joonzis.ex; // 국내에 거주하는 사람 public class Ex02_Local { // 필드// 초기화 상태 (field 값은 초기화 되어있다.) String name;// null int age;// 0 String sn;// null// 주민등록번호 boolean isKorean;// false// 한국인 : true, 외국인 : false // 메소드 void setLocalInfo(String _name, int _age, String _sn) { // 이름, 나이, 주민등록번호를 전달받아 초기화 // 주민등록번호 뒷 자리의 첫 번째 값이 1~4 일 경우 한국인 name = _name; age = _age; sn = _sn; // 1. charAt() isKore..
package org.joonzis.ex; public class Ex01_Rect { // 필드 int width;// 너비 int height;// 높이 boolean isSquare;// 정사각형 유무 - 직사각형:false , 정사각형:true // 메소드 // 1. 필드 초기화 메소드 void setFields(int w, int h) { width = w; height = h; isSquare = (w==h) ? true : false; } void setFields(int side) { width = side; height = side; isSquare = true; } // 2. 사각형 크기 계산 메소드 int calcArea() { int result = width * height; re..
Q1. 클래스 Circle - 필드 : radius, PI, name - 메소드 : info 클래스 CircleMain - 메소드 : main 값을 대입해서 반지름, 이름, 크기(PI*R*R), 둘레(2*PI*R) 값 출력 Q2. 클래스 Rect - 필드 : width, height - 메소드 : init(너비, 높이 입력), info(너비, 높이, 크기(calcArea) 출력), calcArea(w*h, 넓이계산(크기) 출력) 클래스 RectMain - 메소드 : main 값을 입력 받아서 (Scanner) 확인 Q3. 클래스 Triangle - 필드 : width, height - 메소드 : init(너비, 높이 입력), info(너비, 높이, 크기 출력), calcArea(w*h/2 넓이계산 후 리..
package org.joonzis.ex; class Person{ // 필드 char gender; int age; double height; String name; // 메소드 void info() { System.out.println("성별 : " + gender); System.out.println("나이 : " + age); System.out.println("키 : " + height); System.out.println("이름 : " + name); } } public class Ex02_PersonMain { public static void main(String[] args) { Person woman = new Person(); woman.gender = '여'; woman.age = ..
package org.joonzis.ex; public class Ex01_Book { // 필드 String title; String writer; int price; boolean isBestSeller; // 메소드 void info() { System.out.println("제목 : " + title); System.out.println("저자 : " + writer); System.out.println("가격 : " + price); System.out.println(isBestSeller ? "베스트셀러" : "일반서적"); } } package org.joonzis.ex; public class Ex01_BookMain { public static void main(String[] args)..
package org.joonzis.test; public class Test01 { public static void main(String[] args) { //Test01.java //Q. 임의의 정수값 5개를 저장한 배열 중에서 인덱스가 1인 곳의 값을 출력 // 1. 배열 선언int[] arr = new int[5]; // 2. 배열 초기화int[] arr = {1,2,3,4,5}; // 1. 임의의 정수값 5개를 저장한 배열 만들기 // 2. 해당 배열의 1번 인덱스 값 출력 int[] arr = {1,2,3,4,5}; System.out.println(arr[1]); } } package org.joonzis.test; public class Test02 { public static void ..