From d342b2643414af01ea0b0d0368bd658b9216a392 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 18 Jan 2023 18:28:05 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=EC=A0=84=EB=8B=A4=EB=B9=88=20Report1,=202?= =?UTF-8?q?=20=EC=A0=9C=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jeondabeen/report1/Report1_1 | 6 +++++ src/jeondabeen/report1/Report1_2 | 9 +++++++ src/jeondabeen/report1/Report1_3.java | 36 +++++++++++++++++++++++++++ src/jeondabeen/report2/Report2_1 | 5 ++++ src/jeondabeen/report2/Report2_2.java | 20 +++++++++++++++ src/jeondabeen/report2/Report2_3.java | 8 ++++++ src/jeondabeen/report2/Report2_4.java | 11 ++++++++ src/jeondabeen/report2/Report2_5.java | 8 ++++++ src/jeondabeen/report2/Report2_6.java | 14 +++++++++++ 9 files changed, 117 insertions(+) create mode 100644 src/jeondabeen/report1/Report1_1 create mode 100644 src/jeondabeen/report1/Report1_2 create mode 100644 src/jeondabeen/report1/Report1_3.java create mode 100644 src/jeondabeen/report2/Report2_1 create mode 100644 src/jeondabeen/report2/Report2_2.java create mode 100644 src/jeondabeen/report2/Report2_3.java create mode 100644 src/jeondabeen/report2/Report2_4.java create mode 100644 src/jeondabeen/report2/Report2_5.java create mode 100644 src/jeondabeen/report2/Report2_6.java diff --git a/src/jeondabeen/report1/Report1_1 b/src/jeondabeen/report1/Report1_1 new file mode 100644 index 0000000..669a33d --- /dev/null +++ b/src/jeondabeen/report1/Report1_1 @@ -0,0 +1,6 @@ +2-4번 문제 + +정답 : byte b = 256; => overflow 발생 + char c = ''; => char 타입은 빈 문자 불가능 + char answer = 'no'; => char 타입은 문자 하나만 가능 + float f = 3.14 => float 타입이기 때문에 리터럴에 접미사 f 붙여야 하고, 끝에 세미콜론 붙여야 함 \ No newline at end of file diff --git a/src/jeondabeen/report1/Report1_2 b/src/jeondabeen/report1/Report1_2 new file mode 100644 index 0000000..393eee8 --- /dev/null +++ b/src/jeondabeen/report1/Report1_2 @@ -0,0 +1,9 @@ +2-7번 번 문제 + +정답 : System.out.println("1" + "2"); => 3 + System.out.println(true+""); => true + System.out.println('A' + 'B'); => 65 + 66 = 131 + System.out.println('1' + 2); => 49 + 2 = 51 + System.out.println('1' + '2'); => 49 + 50 = 99 + System.out.println('J' +"ava"); => Java + System.out.println(true + null); => 오류 \ No newline at end of file diff --git a/src/jeondabeen/report1/Report1_3.java b/src/jeondabeen/report1/Report1_3.java new file mode 100644 index 0000000..bc8c3b9 --- /dev/null +++ b/src/jeondabeen/report1/Report1_3.java @@ -0,0 +1,36 @@ +package jeondabeen.report1; +// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수 +public class Report1_3 { + public static void main(String[] args) { + int x = 1; + int y = 2; + int z = 3; + + int tmp = x; + x = y; + y = tmp; + tmp = z; + z = y; + y = tmp; + + //예상 결과 : x=2, y=3, z=1 + System.out.println("x="+x); + System.out.println("y="+y); + System.out.println("z="+z); + + byte b = 10; + char ch = 'A'; + int i = 100; + long l = 1000L; + + AddClass addClass = new AddClass(); + addClass.test(); + } +} + +// 필요하다면 클래스 추가 +class AddClass { + void test() { + System.out.println("AddClass.test"); + } +} diff --git a/src/jeondabeen/report2/Report2_1 b/src/jeondabeen/report2/Report2_1 new file mode 100644 index 0000000..c743ec2 --- /dev/null +++ b/src/jeondabeen/report2/Report2_1 @@ -0,0 +1,5 @@ +3-1번 문제 + +정답 : b = (byte)i; + float f = (float)l; => 실수형이 정수형보다 더 크기 때문 + i = (int)ch; \ No newline at end of file diff --git a/src/jeondabeen/report2/Report2_2.java b/src/jeondabeen/report2/Report2_2.java new file mode 100644 index 0000000..bfb697a --- /dev/null +++ b/src/jeondabeen/report2/Report2_2.java @@ -0,0 +1,20 @@ +package jeondabeen.report2; +// 3-2번 문제 +public class Report2_2 { + public static void main(String[] args) { + int x = 2; + int y = 5; + char c = 'A'; // 'A'의 문자코드는 65 + + System.out.println(y >= 5 || x < 0 && x > 2); // true || false && false -> true || false -> true => ||보다 &&가 우선순위 높음 + System.out.println(y += 10 - x++); // y += 10 - 2 -> y = y + 8 -> y = 13 -> (x = 3) + System.out.println(x += 2); // x = x + 2 -> x = 5 + System.out.println(!('A' <= c && c <= 'Z')); // !(true && true) -> !true -> false + System.out.println('C' - c); // 67 - 65 = 2 + System.out.println('5' - '0'); // 5 + System.out.println(c + 1); // 65 + 1 = 66 + System.out.println(++c); // B => 증감연산자 반환 타입은 피연산자랑 같음 + System.out.println(c++); // B => 후위형 증감연산, 메서드 호출 후 증가 + System.out.println(c); // C + } +} diff --git a/src/jeondabeen/report2/Report2_3.java b/src/jeondabeen/report2/Report2_3.java new file mode 100644 index 0000000..1d01a30 --- /dev/null +++ b/src/jeondabeen/report2/Report2_3.java @@ -0,0 +1,8 @@ +package jeondabeen.report2; + +public class Report2_3 { + public static void main(String[] args){ + int num = 456; + System.out.println(num / 100 * 100); + } +} diff --git a/src/jeondabeen/report2/Report2_4.java b/src/jeondabeen/report2/Report2_4.java new file mode 100644 index 0000000..2bbda75 --- /dev/null +++ b/src/jeondabeen/report2/Report2_4.java @@ -0,0 +1,11 @@ +package jeondabeen.report2; + +public class Report2_4 { + public static void main(String[] args){ + int numOfApples = 123; // 사과의 개수 + int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수) + int numOfBucket = numOfApples % sizeOfBucket > 0 ? numOfApples / sizeOfBucket + 1 : numOfApples / sizeOfBucket; // 모든 사과를 담는데 필요한 바구니의 수 + + System.out.println("필요한 바구니의 수 :"+numOfBucket); + } +} diff --git a/src/jeondabeen/report2/Report2_5.java b/src/jeondabeen/report2/Report2_5.java new file mode 100644 index 0000000..faaaca0 --- /dev/null +++ b/src/jeondabeen/report2/Report2_5.java @@ -0,0 +1,8 @@ +package jeondabeen.report2; + +public class Report2_5 { + public static void main(String[] args) { + int num = 10; + System.out.println(num > 0 ? "양수" : (num < 0 ? "음수" : "0")); + } +} diff --git a/src/jeondabeen/report2/Report2_6.java b/src/jeondabeen/report2/Report2_6.java new file mode 100644 index 0000000..b7e2806 --- /dev/null +++ b/src/jeondabeen/report2/Report2_6.java @@ -0,0 +1,14 @@ +package jeondabeen.report2; + +public class Report2_6 { + public static void main(String[] args){ + int fahrenheit = 100; + float celcius = 5F / 9 * (fahrenheit - 32); + int tmp = (int) (celcius * 1000); + float result = tmp % 10 >= 5 ? (tmp - (tmp % 10) + 10) / 1000F : tmp - (tmp % 10) / 1000F; + + System.out.println("Fahrenheit:" + fahrenheit); + System.out.println("Celcius:" + result); + //예상 결과 : Fahrenheit:100, Celcius:37.78 + } +} From 88fa74559c0af5814b9af431c1cf3f5c2b01d85f Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 18 Jan 2023 18:52:44 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=EC=A0=84=EB=8B=A4=EB=B9=88=20Report1,=202?= =?UTF-8?q?=20=EC=A0=9C=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jeondabeen/report1/Report1_1 | 6 +++++ src/jeondabeen/report1/Report1_2 | 9 +++++++ src/jeondabeen/report1/Report1_3.java | 36 +++++++++++++++++++++++++++ src/jeondabeen/report2/Report2_1 | 5 ++++ src/jeondabeen/report2/Report2_2.java | 20 +++++++++++++++ src/jeondabeen/report2/Report2_3.java | 8 ++++++ src/jeondabeen/report2/Report2_4.java | 11 ++++++++ src/jeondabeen/report2/Report2_5.java | 8 ++++++ src/jeondabeen/report2/Report2_6.java | 14 +++++++++++ 9 files changed, 117 insertions(+) create mode 100644 src/jeondabeen/report1/Report1_1 create mode 100644 src/jeondabeen/report1/Report1_2 create mode 100644 src/jeondabeen/report1/Report1_3.java create mode 100644 src/jeondabeen/report2/Report2_1 create mode 100644 src/jeondabeen/report2/Report2_2.java create mode 100644 src/jeondabeen/report2/Report2_3.java create mode 100644 src/jeondabeen/report2/Report2_4.java create mode 100644 src/jeondabeen/report2/Report2_5.java create mode 100644 src/jeondabeen/report2/Report2_6.java diff --git a/src/jeondabeen/report1/Report1_1 b/src/jeondabeen/report1/Report1_1 new file mode 100644 index 0000000..669a33d --- /dev/null +++ b/src/jeondabeen/report1/Report1_1 @@ -0,0 +1,6 @@ +2-4번 문제 + +정답 : byte b = 256; => overflow 발생 + char c = ''; => char 타입은 빈 문자 불가능 + char answer = 'no'; => char 타입은 문자 하나만 가능 + float f = 3.14 => float 타입이기 때문에 리터럴에 접미사 f 붙여야 하고, 끝에 세미콜론 붙여야 함 \ No newline at end of file diff --git a/src/jeondabeen/report1/Report1_2 b/src/jeondabeen/report1/Report1_2 new file mode 100644 index 0000000..393eee8 --- /dev/null +++ b/src/jeondabeen/report1/Report1_2 @@ -0,0 +1,9 @@ +2-7번 번 문제 + +정답 : System.out.println("1" + "2"); => 3 + System.out.println(true+""); => true + System.out.println('A' + 'B'); => 65 + 66 = 131 + System.out.println('1' + 2); => 49 + 2 = 51 + System.out.println('1' + '2'); => 49 + 50 = 99 + System.out.println('J' +"ava"); => Java + System.out.println(true + null); => 오류 \ No newline at end of file diff --git a/src/jeondabeen/report1/Report1_3.java b/src/jeondabeen/report1/Report1_3.java new file mode 100644 index 0000000..bc8c3b9 --- /dev/null +++ b/src/jeondabeen/report1/Report1_3.java @@ -0,0 +1,36 @@ +package jeondabeen.report1; +// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수 +public class Report1_3 { + public static void main(String[] args) { + int x = 1; + int y = 2; + int z = 3; + + int tmp = x; + x = y; + y = tmp; + tmp = z; + z = y; + y = tmp; + + //예상 결과 : x=2, y=3, z=1 + System.out.println("x="+x); + System.out.println("y="+y); + System.out.println("z="+z); + + byte b = 10; + char ch = 'A'; + int i = 100; + long l = 1000L; + + AddClass addClass = new AddClass(); + addClass.test(); + } +} + +// 필요하다면 클래스 추가 +class AddClass { + void test() { + System.out.println("AddClass.test"); + } +} diff --git a/src/jeondabeen/report2/Report2_1 b/src/jeondabeen/report2/Report2_1 new file mode 100644 index 0000000..c743ec2 --- /dev/null +++ b/src/jeondabeen/report2/Report2_1 @@ -0,0 +1,5 @@ +3-1번 문제 + +정답 : b = (byte)i; + float f = (float)l; => 실수형이 정수형보다 더 크기 때문 + i = (int)ch; \ No newline at end of file diff --git a/src/jeondabeen/report2/Report2_2.java b/src/jeondabeen/report2/Report2_2.java new file mode 100644 index 0000000..bfb697a --- /dev/null +++ b/src/jeondabeen/report2/Report2_2.java @@ -0,0 +1,20 @@ +package jeondabeen.report2; +// 3-2번 문제 +public class Report2_2 { + public static void main(String[] args) { + int x = 2; + int y = 5; + char c = 'A'; // 'A'의 문자코드는 65 + + System.out.println(y >= 5 || x < 0 && x > 2); // true || false && false -> true || false -> true => ||보다 &&가 우선순위 높음 + System.out.println(y += 10 - x++); // y += 10 - 2 -> y = y + 8 -> y = 13 -> (x = 3) + System.out.println(x += 2); // x = x + 2 -> x = 5 + System.out.println(!('A' <= c && c <= 'Z')); // !(true && true) -> !true -> false + System.out.println('C' - c); // 67 - 65 = 2 + System.out.println('5' - '0'); // 5 + System.out.println(c + 1); // 65 + 1 = 66 + System.out.println(++c); // B => 증감연산자 반환 타입은 피연산자랑 같음 + System.out.println(c++); // B => 후위형 증감연산, 메서드 호출 후 증가 + System.out.println(c); // C + } +} diff --git a/src/jeondabeen/report2/Report2_3.java b/src/jeondabeen/report2/Report2_3.java new file mode 100644 index 0000000..1d01a30 --- /dev/null +++ b/src/jeondabeen/report2/Report2_3.java @@ -0,0 +1,8 @@ +package jeondabeen.report2; + +public class Report2_3 { + public static void main(String[] args){ + int num = 456; + System.out.println(num / 100 * 100); + } +} diff --git a/src/jeondabeen/report2/Report2_4.java b/src/jeondabeen/report2/Report2_4.java new file mode 100644 index 0000000..2bbda75 --- /dev/null +++ b/src/jeondabeen/report2/Report2_4.java @@ -0,0 +1,11 @@ +package jeondabeen.report2; + +public class Report2_4 { + public static void main(String[] args){ + int numOfApples = 123; // 사과의 개수 + int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수) + int numOfBucket = numOfApples % sizeOfBucket > 0 ? numOfApples / sizeOfBucket + 1 : numOfApples / sizeOfBucket; // 모든 사과를 담는데 필요한 바구니의 수 + + System.out.println("필요한 바구니의 수 :"+numOfBucket); + } +} diff --git a/src/jeondabeen/report2/Report2_5.java b/src/jeondabeen/report2/Report2_5.java new file mode 100644 index 0000000..faaaca0 --- /dev/null +++ b/src/jeondabeen/report2/Report2_5.java @@ -0,0 +1,8 @@ +package jeondabeen.report2; + +public class Report2_5 { + public static void main(String[] args) { + int num = 10; + System.out.println(num > 0 ? "양수" : (num < 0 ? "음수" : "0")); + } +} diff --git a/src/jeondabeen/report2/Report2_6.java b/src/jeondabeen/report2/Report2_6.java new file mode 100644 index 0000000..b7e2806 --- /dev/null +++ b/src/jeondabeen/report2/Report2_6.java @@ -0,0 +1,14 @@ +package jeondabeen.report2; + +public class Report2_6 { + public static void main(String[] args){ + int fahrenheit = 100; + float celcius = 5F / 9 * (fahrenheit - 32); + int tmp = (int) (celcius * 1000); + float result = tmp % 10 >= 5 ? (tmp - (tmp % 10) + 10) / 1000F : tmp - (tmp % 10) / 1000F; + + System.out.println("Fahrenheit:" + fahrenheit); + System.out.println("Celcius:" + result); + //예상 결과 : Fahrenheit:100, Celcius:37.78 + } +} From b5643aeb4f3c3a99734ba8ea6735eb6762e8f60d Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 19 Jan 2023 21:54:46 +0900 Subject: [PATCH 3/8] add: report3,4 --- src/jeondabeen/report3/Report3_1 | 25 +++++++++++++++++++ src/jeondabeen/report3/Report3_10.java | 28 ++++++++++++++++++++++ src/jeondabeen/report3/Report3_2.java | 13 ++++++++++ src/jeondabeen/report3/Report3_3.java | 15 ++++++++++++ src/jeondabeen/report3/Report3_4.java | 23 ++++++++++++++++++ src/jeondabeen/report3/Report3_5.java | 12 ++++++++++ src/jeondabeen/report3/Report3_6.java | 13 ++++++++++ src/jeondabeen/report3/Report3_7.java | 15 ++++++++++++ src/jeondabeen/report3/Report3_8.java | 8 +++++++ src/jeondabeen/report3/Report3_9.java | 17 +++++++++++++ src/jeondabeen/report3/flow chart.png | Bin 0 -> 18374 bytes src/jeondabeen/report4/Report4_1 | 5 ++++ src/jeondabeen/report4/Report4_2 | 8 +++++++ src/jeondabeen/report4/Report4_3.java | 15 ++++++++++++ src/jeondabeen/report4/Report4_4.java | 28 ++++++++++++++++++++++ src/jeondabeen/report4/Report4_5.java | 31 ++++++++++++++++++++++++ src/jeondabeen/report4/Report4_6.java | 32 +++++++++++++++++++++++++ 17 files changed, 288 insertions(+) create mode 100644 src/jeondabeen/report3/Report3_1 create mode 100644 src/jeondabeen/report3/Report3_10.java create mode 100644 src/jeondabeen/report3/Report3_2.java create mode 100644 src/jeondabeen/report3/Report3_3.java create mode 100644 src/jeondabeen/report3/Report3_4.java create mode 100644 src/jeondabeen/report3/Report3_5.java create mode 100644 src/jeondabeen/report3/Report3_6.java create mode 100644 src/jeondabeen/report3/Report3_7.java create mode 100644 src/jeondabeen/report3/Report3_8.java create mode 100644 src/jeondabeen/report3/Report3_9.java create mode 100644 src/jeondabeen/report3/flow chart.png create mode 100644 src/jeondabeen/report4/Report4_1 create mode 100644 src/jeondabeen/report4/Report4_2 create mode 100644 src/jeondabeen/report4/Report4_3.java create mode 100644 src/jeondabeen/report4/Report4_4.java create mode 100644 src/jeondabeen/report4/Report4_5.java create mode 100644 src/jeondabeen/report4/Report4_6.java diff --git a/src/jeondabeen/report3/Report3_1 b/src/jeondabeen/report3/Report3_1 new file mode 100644 index 0000000..a98d5f2 --- /dev/null +++ b/src/jeondabeen/report3/Report3_1 @@ -0,0 +1,25 @@ +//4-1. 다음의 문장들을 조건식으로 표현해보세요. + +//int형 변수 x가 10보다 크고 20보다 작을 때 true인 조건식 +if (x > 10 && x < 20) + +//char형 변수 ch가 공백이나 탭이 아닐 때 true인 조건식 +if (ch != '\n' && ch != '\t') + +//char형 변수 ch가 'x' 또는 'X'일 때 true인 조건식 +if (ch == 'x' || ch == 'X') + +//char형 변수 ch가 숫자('0'~'9')일 때 true인 조건식 +if (ch >= '0' && ch <= '9') + +//char형 변수 ch가 영문자(대문자 또는 소문자)일 때 true인 조건식 +if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) + +//int형 변수 year가 400으로 나눠떨어지거나 또는 4로 나눠떨어지고 100으로 나눠떨어지지 않을때 true인 조건식 +if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) + +//boolean형 변수 powerOn이 false일 때 true인 조건식 +if (!powerOn) + +//문자열 참조변수 str이 "yes"일 때 true인 조건식 +if (str.equals("yes")) \ No newline at end of file diff --git a/src/jeondabeen/report3/Report3_10.java b/src/jeondabeen/report3/Report3_10.java new file mode 100644 index 0000000..e8df7a7 --- /dev/null +++ b/src/jeondabeen/report3/Report3_10.java @@ -0,0 +1,28 @@ +package jeondabeen.report3; + +public class Report3_10 { + public static void main(String[] args) { + // 1~100사이의 임의의 값을 얻어서 answer에 저장한다. + int answer = (int) (Math.random() * 100) + 1; + int input = 0; //사용자입력을 저장할 공간 + int count = 0; //시도횟수를 세기위한 변수 + + // 화면으로 부터 사용자입력을 받기 위해서 Scanner클래스 사용 + java.util.Scanner s = new java.util.Scanner(System.in); + do { + count++; + System.out.print("1과 100사이의 값을 입력하세요 : "); + input = s.nextInt(); //입력받은 값을 변수 input에 저장한다. + + if (input < answer) { + System.out.println("더 큰 수를 입력하세요."); + } else if (input > answer) { + System.out.println("더 작은 수를 입력하세요."); + } else { + System.out.println("맞혔습니다."); + System.out.println("시도횟수는 " + count + "번입니다."); + break; + } + } while(true); //무한반복문 + } +} diff --git a/src/jeondabeen/report3/Report3_2.java b/src/jeondabeen/report3/Report3_2.java new file mode 100644 index 0000000..ccff918 --- /dev/null +++ b/src/jeondabeen/report3/Report3_2.java @@ -0,0 +1,13 @@ +package jeondabeen.report3; + +public class Report3_2 { + public static void main(String[] args) { + int sum = 0; + + for (int i = 1; i <= 20; i++) { + if (i % 2 == 0 || i % 3 == 0) continue; + sum += i; + } + System.out.println("sum=" + sum); + } +} diff --git a/src/jeondabeen/report3/Report3_3.java b/src/jeondabeen/report3/Report3_3.java new file mode 100644 index 0000000..1f72621 --- /dev/null +++ b/src/jeondabeen/report3/Report3_3.java @@ -0,0 +1,15 @@ +package jeondabeen.report3; + +public class Report3_3 { + public static void main(String[] args) { + int sum = 0; + int totalSum = 0; + + for (int i = 1; i <= 10; i++) { + sum += i; + totalSum += sum; + } + + System.out.println("totalSum="+totalSum); + } +} diff --git a/src/jeondabeen/report3/Report3_4.java b/src/jeondabeen/report3/Report3_4.java new file mode 100644 index 0000000..4bac111 --- /dev/null +++ b/src/jeondabeen/report3/Report3_4.java @@ -0,0 +1,23 @@ +package jeondabeen.report3; + +public class Report3_4 { + public static void main(String[] args) { + int sum = 0; // 총합을 저장할 변수 + int s = 1; // 값의 부호를 바꿔주는데 사용할 변수 + int num = 0; + + while (sum < 100) { + if (num != 0 && num % 2 == 0) { + s = 1; + } else if (num % 2 != 0) { + s = -1; + } + + num = (Math.abs(num) + 1) * s; + sum += num; + } + System.out.println(); + System.out.println("num="+num); + System.out.println("sum="+sum); + } +} diff --git a/src/jeondabeen/report3/Report3_5.java b/src/jeondabeen/report3/Report3_5.java new file mode 100644 index 0000000..0b18820 --- /dev/null +++ b/src/jeondabeen/report3/Report3_5.java @@ -0,0 +1,12 @@ +package jeondabeen.report3; + +public class Report3_5 { + public static void main(String[] args) { + int k = 0; + while (k <= 10) { + System.out.print("*".repeat(k + 1)); + System.out.println(); + k++; + } + } +} diff --git a/src/jeondabeen/report3/Report3_6.java b/src/jeondabeen/report3/Report3_6.java new file mode 100644 index 0000000..e080038 --- /dev/null +++ b/src/jeondabeen/report3/Report3_6.java @@ -0,0 +1,13 @@ +package jeondabeen.report3; + +public class Report3_6 { + public static void main(String[] args) { + for (int i = 1; i <= 6; i++) { + for (int j = 1; j < 6; j++) { + if (i + j == 6) { + System.out.println("[" + i + ", " + j + "]"); + } + } + } + } +} diff --git a/src/jeondabeen/report3/Report3_7.java b/src/jeondabeen/report3/Report3_7.java new file mode 100644 index 0000000..50f4a65 --- /dev/null +++ b/src/jeondabeen/report3/Report3_7.java @@ -0,0 +1,15 @@ +package jeondabeen.report3; + +public class Report3_7 { + public static void main(String[] args) { + String str = "12345"; + int sum = 0; + + for (int i = 0; i < str.length(); i++) { + sum += str.charAt(i) - '0'; + } + + //예상 결과 : sum=15 + System.out.println("sum=" + sum); + } +} diff --git a/src/jeondabeen/report3/Report3_8.java b/src/jeondabeen/report3/Report3_8.java new file mode 100644 index 0000000..d4d1fb9 --- /dev/null +++ b/src/jeondabeen/report3/Report3_8.java @@ -0,0 +1,8 @@ +package jeondabeen.report3; + +public class Report3_8 { + public static void main(String[] args){ + int value = (int) (Math.random() * 6) + 1; + System.out.println("value:"+value); + } +} diff --git a/src/jeondabeen/report3/Report3_9.java b/src/jeondabeen/report3/Report3_9.java new file mode 100644 index 0000000..de3f7c4 --- /dev/null +++ b/src/jeondabeen/report3/Report3_9.java @@ -0,0 +1,17 @@ +package jeondabeen.report3; + +import java.util.Arrays; + +public class Report3_9 { + public static void main(String[] args) { + int num = 12345; + int sum = 0; + + while (num > 0) { + sum += num % 10; + num /= 10; + } + + System.out.println("sum="+sum); + } +} diff --git a/src/jeondabeen/report3/flow chart.png b/src/jeondabeen/report3/flow chart.png new file mode 100644 index 0000000000000000000000000000000000000000..0aefbccb7424dfd710026c46bead7cf992674d8f GIT binary patch literal 18374 zcmd_RXH-;6v@W^;0hP3g5(E@PLOpK;C@cbs4E+&9L3kD;(?ty)#HYR#JU%{jk{($P|;xXgSRf*=Z2 z6@(u6I}AaD+80T{727zoEcips~_6Y#UA2PO{BHI>;1+o9>Tc(VcC@$qr;ZRz2+ju+NL|WsldicLL+p$JzT} z?exUFH54>K5s<QPTqLxMEdZk+#}KrsBFPj`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cmV?d00001 diff --git a/src/jeondabeen/report4/Report4_1 b/src/jeondabeen/report4/Report4_1 new file mode 100644 index 0000000..e20530e --- /dev/null +++ b/src/jeondabeen/report4/Report4_1 @@ -0,0 +1,5 @@ +int[] arr[]; +=> int[] arr; OR int arr[]; + +int[] arr[] = new int[3][]; +=> int[][] arr = new int[3][]; OR int arr[][] = new int[3][]; \ No newline at end of file diff --git a/src/jeondabeen/report4/Report4_2 b/src/jeondabeen/report4/Report4_2 new file mode 100644 index 0000000..f22e2fd --- /dev/null +++ b/src/jeondabeen/report4/Report4_2 @@ -0,0 +1,8 @@ +int[][]arr ={ + {5,5,5,5,5}, + {10,10,10}, + {20,20,20,20}, + {30,30} +}; + +arr[3].length => 2 \ No newline at end of file diff --git a/src/jeondabeen/report4/Report4_3.java b/src/jeondabeen/report4/Report4_3.java new file mode 100644 index 0000000..898144c --- /dev/null +++ b/src/jeondabeen/report4/Report4_3.java @@ -0,0 +1,15 @@ +package jeondabeen.report4; + +public class Report4_3 { + public static void main(String[] args){ + int[] arr = {10, 20, 30, 40, 50}; + int sum = 0; + + for (int num : arr) { + sum += num; + } + + //예상 결과 : sum=150 + System.out.println("sum="+sum); + } +} diff --git a/src/jeondabeen/report4/Report4_4.java b/src/jeondabeen/report4/Report4_4.java new file mode 100644 index 0000000..c166aee --- /dev/null +++ b/src/jeondabeen/report4/Report4_4.java @@ -0,0 +1,28 @@ +package jeondabeen.report4; + +public class Report4_4 { + public static void main(String[] args) { + int[][] arr = { + { 5, 5, 5, 5, 5 }, + { 10, 10, 10, 10, 10 }, + { 20, 20, 20, 20, 20 }, + { 30, 30, 30, 30, 30 } + }; + + int total = 0; + float average = 0; + + int numCount = 0; + for (int[] ints : arr) { + for (int num : ints) { + total += num; + numCount++; + } + } + + average = (float) total / numCount; + + System.out.println("total=" + total); + System.out.println("average=" + average); + } +} diff --git a/src/jeondabeen/report4/Report4_5.java b/src/jeondabeen/report4/Report4_5.java new file mode 100644 index 0000000..f1fbdb4 --- /dev/null +++ b/src/jeondabeen/report4/Report4_5.java @@ -0,0 +1,31 @@ +package jeondabeen.report4; + +import java.util.Arrays; + +public class Report4_5 { + public static void main(String[] args) { + int[] ballArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int[] ball3 = new int[3]; + + // 배열 ballArr의 임의의 요소를 골라서 위치를 바꾼다 + for (int i = 0; i < ballArr.length; i++) { + int j = (int) (Math.random() * ballArr.length); + int tmp = 0; + + tmp = ballArr[i]; + ballArr[i] = ballArr[j]; + ballArr[j] = tmp; + } + + for (int i = 0; i < 3; i++) { + ball3[i] = ballArr[i]; + } + + // 배열 ballArr의 앞에서 3개의 수를 배열 ball3로 복사한다 + ball3 = Arrays.copyOf(ballArr, 3); + + for (int i = 0; i < ball3.length; i++) { + System.out.print(ball3[i]); + } + } +} diff --git a/src/jeondabeen/report4/Report4_6.java b/src/jeondabeen/report4/Report4_6.java new file mode 100644 index 0000000..a742fc7 --- /dev/null +++ b/src/jeondabeen/report4/Report4_6.java @@ -0,0 +1,32 @@ +package jeondabeen.report4; + +import java.util.Scanner; + +public class Report4_6 { + public static void main(String args[]) { + String[] words = { "television", "computer", "mouse", "phone" }; + + Scanner scanner = new Scanner(System.in); + + for (int i = 0; i < words.length; i++) { + char[] question = words[i].toCharArray(); // String을 char[]로 변환 + + for (int j = 0; j < question.length; j++) { + int k = (int) (Math.random() * question.length); + + char tmp = question[j]; + question[j] = question[k]; + question[k] = tmp; + } + + System.out.printf("Q%d. %s의 정답을 입력하세요 .>", i + 1, new String(question)); + String answer = scanner.nextLine(); + + // trim()으로 answer의 좌우 공백을 제거한 후, equals로 word[i]와 비교 + if (words[i].equals(answer.trim())) + System.out.printf("맞았습니다.%n%n"); + else + System.out.printf("틀렸습니다.%n%n"); + } + } +} From e5c4e4f7047e8df862703a2b5192d3b03fccfad9 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 19 Jan 2023 22:21:14 +0900 Subject: [PATCH 4/8] modify: report1_3 --- src/jeondabeen/report1/Report1_3.java | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/jeondabeen/report1/Report1_3.java b/src/jeondabeen/report1/Report1_3.java index bc8c3b9..b87c63a 100644 --- a/src/jeondabeen/report1/Report1_3.java +++ b/src/jeondabeen/report1/Report1_3.java @@ -8,29 +8,12 @@ public static void main(String[] args) { int tmp = x; x = y; - y = tmp; - tmp = z; - z = y; - y = tmp; + y = z; + z = tmp; //예상 결과 : x=2, y=3, z=1 System.out.println("x="+x); System.out.println("y="+y); System.out.println("z="+z); - - byte b = 10; - char ch = 'A'; - int i = 100; - long l = 1000L; - - AddClass addClass = new AddClass(); - addClass.test(); - } -} - -// 필요하다면 클래스 추가 -class AddClass { - void test() { - System.out.println("AddClass.test"); } } From db3d476e360a72b6538f10d89a97483019f0dba0 Mon Sep 17 00:00:00 2001 From: jan Date: Sat, 21 Jan 2023 12:17:17 +0900 Subject: [PATCH 5/8] add: report5 --- src/jeondabeen/report5/Report5_1 | 12 ++++++++++ src/jeondabeen/report5/Report5_2.java | 10 ++++++++ src/jeondabeen/report5/Report5_3.java | 17 ++++++++++++++ src/jeondabeen/report5/Report5_4.java | 15 ++++++++++++ src/jeondabeen/report5/Report5_5.java | 23 ++++++++++++++++++ src/jeondabeen/report5/Student.java | 34 +++++++++++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 src/jeondabeen/report5/Report5_1 create mode 100644 src/jeondabeen/report5/Report5_2.java create mode 100644 src/jeondabeen/report5/Report5_3.java create mode 100644 src/jeondabeen/report5/Report5_4.java create mode 100644 src/jeondabeen/report5/Report5_5.java create mode 100644 src/jeondabeen/report5/Student.java diff --git a/src/jeondabeen/report5/Report5_1 b/src/jeondabeen/report5/Report5_1 new file mode 100644 index 0000000..a1e152f --- /dev/null +++ b/src/jeondabeen/report5/Report5_1 @@ -0,0 +1,12 @@ +//6-1. 다음과 같은 멤버 변수를 갖는 Student 클래스를 정의하세요. +//타입 : String, 변수명 : name, 설명 : 학생 이름 +//타입 : int, 변수명 : ban, 설명 : 반 +//타입 : int, 변수명 : no, 설명 : 번호 +//타입 : int, 변수명 : kor, 설명 : 국어 점수 +//타입 : int, 변수명 : eng, 설명 : 영어 점수 +//타입 : int, 변수명 : math, 설명 : 수학 점수 + +class Student { + String name; + int ban, no, kor, eng, math; +} diff --git a/src/jeondabeen/report5/Report5_2.java b/src/jeondabeen/report5/Report5_2.java new file mode 100644 index 0000000..a0dc649 --- /dev/null +++ b/src/jeondabeen/report5/Report5_2.java @@ -0,0 +1,10 @@ +package jeondabeen.report5; + +public class Report5_2 { + public static void main(String[] args){ + Student s = new Student("홍길동", 1, 1, 100, 60, 76); + + String str = s.info(); + System.out.println(str); + }// 예상 결과 : 홍길동, 1, 1, 100, 60, 76, 236, 78.7 +} diff --git a/src/jeondabeen/report5/Report5_3.java b/src/jeondabeen/report5/Report5_3.java new file mode 100644 index 0000000..99d35bc --- /dev/null +++ b/src/jeondabeen/report5/Report5_3.java @@ -0,0 +1,17 @@ +package jeondabeen.report5; + +public class Report5_3 { + public static void main(String args[]) { + Student s = new Student(); + s.name = "홍길동"; + s.ban = 1; + s.no = 1; + s.kor = 100; + s.eng = 60; + s.math = 76; + System.out.println("이름 : " + s.name); + System.out.println("총점 : " + s.getTotal()); + System.out.println("평균 : " + s.getAverage()); + }//예상 결과 : 이름 : 홍길동, 총점 : 236, 평균 : 78.7 +} + diff --git a/src/jeondabeen/report5/Report5_4.java b/src/jeondabeen/report5/Report5_4.java new file mode 100644 index 0000000..0887e2f --- /dev/null +++ b/src/jeondabeen/report5/Report5_4.java @@ -0,0 +1,15 @@ +package jeondabeen.report5; + +class PlayingCard { + int kind; // 인스턴스 변수 + int num; // 인스턴스 변수 + static int width; // 클래스 변수 + static int height; // 클래스 변수 + PlayingCard(int k, int n) { // 매개변수 == 지역변수 + kind = k; + num = n; + } + public static void main(String args[]) { // 매개변수 == 지역변수 + PlayingCard card = new PlayingCard(1,1); // 지역변수 + } +} diff --git a/src/jeondabeen/report5/Report5_5.java b/src/jeondabeen/report5/Report5_5.java new file mode 100644 index 0000000..95c008b --- /dev/null +++ b/src/jeondabeen/report5/Report5_5.java @@ -0,0 +1,23 @@ +package jeondabeen.report5; + +public class Report5_5 { + // weapon, armor에 static을 붙여야 한다. + // weapon과 armor는 공유하는/같아야 하는 속성이기 때문이다. +} + +class Marine { + int x=0, y=0; //Marine의 위치좌표 (x,y) + int hp = 60; //현재 체력 + int weapon = 6; //공격력 + int armor = 0; //방어력 + void weaponUp() { + weapon++; + } + void armorUp() { + armor++; + } + void move(int x, int y) { + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/src/jeondabeen/report5/Student.java b/src/jeondabeen/report5/Student.java new file mode 100644 index 0000000..2bf2f9f --- /dev/null +++ b/src/jeondabeen/report5/Student.java @@ -0,0 +1,34 @@ +package jeondabeen.report5; + +class Student{ + String name; + int ban, no, kor, eng, math; + + public Student() { + } + + Student(String name, int ban, int no, int kor, int eng, int math) { + this.name = name; + this.ban = ban; + this.no = no; + this.kor = kor; + this.eng = eng; + this.math = math; + } + + String info() { + // 예상 결과 : 홍길동, 1, 1, 100, 60, 76, 236, 78.7 + int total = kor+eng+math; + float avg = (int) (total / 0.3 + 0.5) / 10f; + + return name + ", " + ban + ", " + no + ", " + kor + ", " + eng + ", " + math + ", " + total + ", " + avg; + } + + int getTotal() { + return kor + eng + math; + } + + float getAverage() { + return (int) (getTotal() / 0.3 + 0.5) / 10f; + } +} \ No newline at end of file From 49aa3ca76c7a5b8ea635b9be447434ed68e83de3 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 24 Jan 2023 23:23:22 +0900 Subject: [PATCH 6/8] add: report6 --- src/jeondabeen/report6/Report6_1.md | 10 ++++++++++ src/jeondabeen/report6/Report6_2.md | 5 +++++ src/jeondabeen/report6/Report6_3.md | 6 ++++++ src/jeondabeen/report6/Report6_4.md | 6 ++++++ src/jeondabeen/report6/Report6_5.md | 8 ++++++++ src/jeondabeen/report6/Report6_6.md | 3 +++ src/jeondabeen/report6/Report6_7.md | 8 ++++++++ src/jeondabeen/report6/Report6_8.md | 4 ++++ src/jeondabeen/report6/Report6_9.md | 17 +++++++++++++++++ src/jeondabeen/report7/Report7_1.java | 2 ++ src/jeondabeen/report7/Report7_2.java | 2 ++ 11 files changed, 71 insertions(+) create mode 100644 src/jeondabeen/report6/Report6_1.md create mode 100644 src/jeondabeen/report6/Report6_2.md create mode 100644 src/jeondabeen/report6/Report6_3.md create mode 100644 src/jeondabeen/report6/Report6_4.md create mode 100644 src/jeondabeen/report6/Report6_5.md create mode 100644 src/jeondabeen/report6/Report6_6.md create mode 100644 src/jeondabeen/report6/Report6_7.md create mode 100644 src/jeondabeen/report6/Report6_8.md create mode 100644 src/jeondabeen/report6/Report6_9.md create mode 100644 src/jeondabeen/report7/Report7_1.java create mode 100644 src/jeondabeen/report7/Report7_2.java diff --git a/src/jeondabeen/report6/Report6_1.md b/src/jeondabeen/report6/Report6_1.md new file mode 100644 index 0000000..0bcd7c4 --- /dev/null +++ b/src/jeondabeen/report6/Report6_1.md @@ -0,0 +1,10 @@ +6-8. 다음 중 생성자에 대한 설명으로 옳지 않은 것은? (모두 고르시오) +b. 생성자는 객체를 생성하기 위한 것이다. +=> 생성자는 인스턴스 초기화를 위해 사용되는 것, 객체를 생성하는 것은 new 연산자이다. + +c. 클래스에는 생성자가 반드시 하나 이상 있어야 한다. +=> 특정한 인자를 받아야 하거나, 인스턴스가 생성되고 바로 실행되어야 할 작업이 없다면 생성자를 만들 필요는 없다. + 생성자가 하나도 없는 클래스라면 컴파일러가 자동으로 기본 생성자를 만들어 주기 때문이다. + +e. 생성자는 오버로딩 할 수 없다. +=> 생성자는 메서드이고, 인스턴스마다 초기화 작업이 다를 수 있기 때문에 오버로딩 가능하다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_2.md b/src/jeondabeen/report6/Report6_2.md new file mode 100644 index 0000000..50793f3 --- /dev/null +++ b/src/jeondabeen/report6/Report6_2.md @@ -0,0 +1,5 @@ +6-9. 다음 중 this에 대한 설명으로 맞지 않은 것은? (모두 고르시오) +b. 클래스 내에서라면 어디서든 사용할 수 있다. +=> 인스턴스 메서드 내에서만 사용할 수 있다. this라는 참조변수는 인스턴스를 가리키는 것이고 + this는 인스턴스 메서드 안에 인스턴스를 가리키는 지역변수로 숨겨져 있다. + 따라서 클래스 메서드에서는 사용할 수 없다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_3.md b/src/jeondabeen/report6/Report6_3.md new file mode 100644 index 0000000..e20fc5e --- /dev/null +++ b/src/jeondabeen/report6/Report6_3.md @@ -0,0 +1,6 @@ +6-10. 다음 중 오버로딩이 성립하기 위한 조건이 아닌 것은? (모두 고르시오) +c. 리턴타입이 달라야 한다. +=> 리턴 타입은 상관 없다! + +d. 매개변수의 이름이 달라야 한다. +=> 매개변수 이름은 상관 없다. 타입과 개수가 달라야 한다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_4.md b/src/jeondabeen/report6/Report6_4.md new file mode 100644 index 0000000..8605d4e --- /dev/null +++ b/src/jeondabeen/report6/Report6_4.md @@ -0,0 +1,6 @@ +6-11. 다음 중 아래의 add메서드를 올바르게 오버로딩 한 것은? (모두 고르시오) +> long add(int a, int b) { return a+b; } + +b. long add(long a, long b) { return a+b; } +c. int add(byte a, byte b) { return a+b; } +d. int add(long a, int b) { return (int)(a+b); } \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_5.md b/src/jeondabeen/report6/Report6_5.md new file mode 100644 index 0000000..3fdc6b2 --- /dev/null +++ b/src/jeondabeen/report6/Report6_5.md @@ -0,0 +1,8 @@ +6-12. 다음 중 초기화에 대한 설명으로 옳지 않은 것은? (모두 고르시오) + +c. 초기화 블럭보다 생성자가 먼저 수행된다. +=> static 초기화 블럭은 항상 생성자보다 먼저 수행되고, + 인스턴스 초기화 블럭은 생성자에 공통된 코드를 넣는데 사용되기 때문에 생성자보다 먼저 수행된다. + +e. 클래스변수보다 인스턴스변수가 먼저 초기화된다. +=> 클래스 변수는 객체가 생성되지 않아도 사용할 수 있어 클래스 변수가 먼저 초기화된다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_6.md b/src/jeondabeen/report6/Report6_6.md new file mode 100644 index 0000000..3bd95e2 --- /dev/null +++ b/src/jeondabeen/report6/Report6_6.md @@ -0,0 +1,3 @@ +6-13. 다음 중 인스턴스변수의 초기화 순서가 올바른 것은? + +a. 기본값-명시적초기화-초기화블럭-생성자 \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_7.md b/src/jeondabeen/report6/Report6_7.md new file mode 100644 index 0000000..3886d43 --- /dev/null +++ b/src/jeondabeen/report6/Report6_7.md @@ -0,0 +1,8 @@ +6-14. 다음 중 지역변수에 대한 설명으로 옳지 않은 것은? (모두 고르시오) + +a. 자동 초기화되므로 별도의 초기화가 필요없다. +=> 자바에서는 지역변수를 수동 초기화 해야한다. + +e. 힙(heap)영역에 생성되며 가비지 컬렉터에 의해 소멸된다. +=> 힙 영역은 인스턴스가 생성되는 곳. 인스턴스 변수가 이 곳에 생성된다. + 지역변수는 call stack에 생성된다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_8.md b/src/jeondabeen/report6/Report6_8.md new file mode 100644 index 0000000..a8e2445 --- /dev/null +++ b/src/jeondabeen/report6/Report6_8.md @@ -0,0 +1,4 @@ +6-15. 호출스택이 다음과 같은 상황일 때 옳지 않은 설명은? (모두 고르시오) + +b. println메서드를 제외한 나머지 메서드들은 모두 종료된 상태이다. +=> 다른 메서드들은 잠시 중지된 상태이다. \ No newline at end of file diff --git a/src/jeondabeen/report6/Report6_9.md b/src/jeondabeen/report6/Report6_9.md new file mode 100644 index 0000000..520eb9c --- /dev/null +++ b/src/jeondabeen/report6/Report6_9.md @@ -0,0 +1,17 @@ +//6-16. 다음 코드의 실행 결과를 예측하여 적어주세요. +```java +class Exercise6_16 { + public static void change(String str) { + str += "456"; + } + + public static void main(String[] args) { + String str = "ABC123"; + System.out.println(str); + change(str); + System.out.println("After change:" + str); + } +} +``` +ABC123 +After change:ABC123456 \ No newline at end of file diff --git a/src/jeondabeen/report7/Report7_1.java b/src/jeondabeen/report7/Report7_1.java new file mode 100644 index 0000000..3301829 --- /dev/null +++ b/src/jeondabeen/report7/Report7_1.java @@ -0,0 +1,2 @@ +package jeondabeen.report7;public class Report7_1 { +} diff --git a/src/jeondabeen/report7/Report7_2.java b/src/jeondabeen/report7/Report7_2.java new file mode 100644 index 0000000..2fc45b8 --- /dev/null +++ b/src/jeondabeen/report7/Report7_2.java @@ -0,0 +1,2 @@ +package jeondabeen.report7;public class Report7_2 { +} From fd90bac0fe2e33a2465c8b2d7bed0139a7628d99 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 25 Jan 2023 10:21:35 +0900 Subject: [PATCH 7/8] add: report7 --- src/jeondabeen/report7/Report7_1.java | 23 +++++++++- src/jeondabeen/report7/Report7_2.java | 20 ++++++++- src/jeondabeen/report7/Report7_3.java | 60 +++++++++++++++++++++++++++ src/jeondabeen/report7/Report7_4.java | 24 +++++++++++ src/jeondabeen/report7/Report7_5.java | 17 ++++++++ 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 src/jeondabeen/report7/Report7_3.java create mode 100644 src/jeondabeen/report7/Report7_4.java create mode 100644 src/jeondabeen/report7/Report7_5.java diff --git a/src/jeondabeen/report7/Report7_1.java b/src/jeondabeen/report7/Report7_1.java index 3301829..bcea22b 100644 --- a/src/jeondabeen/report7/Report7_1.java +++ b/src/jeondabeen/report7/Report7_1.java @@ -1,2 +1,23 @@ -package jeondabeen.report7;public class Report7_1 { +package jeondabeen.report7; + +public class Report7_1 { + static int[] shuffle(int[] arr) { + for (int i = 0; i < arr.length; i++) { + int j = (int) (Math.random() * arr.length); + + int tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + + return arr; + } + + public static void main(String[] args) { + int[] original = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + System.out.println(java.util.Arrays.toString(original)); + + int[] result = shuffle(original); + System.out.println(java.util.Arrays.toString(result)); + } } diff --git a/src/jeondabeen/report7/Report7_2.java b/src/jeondabeen/report7/Report7_2.java index 2fc45b8..7e85eda 100644 --- a/src/jeondabeen/report7/Report7_2.java +++ b/src/jeondabeen/report7/Report7_2.java @@ -1,2 +1,20 @@ -package jeondabeen.report7;public class Report7_2 { +package jeondabeen.report7; + +public class Report7_2 { + static boolean isNumber(String str) { + for (int i = 0; i < str.length(); i++) { + if (!(str.charAt(i) >= '0' && str.charAt(i) <= '9')) return false; + } + + return true; + } + + + public static void main(String[] args) { + String str = "123"; + System.out.println(str + " 는 숫자입니까? " + isNumber(str)); + str = "1234o"; + System.out.println(str + " 는 숫자입니까? " + isNumber(str)); + } + //예상 결과 : 123는 숫자입니까? true, 1234o는 숫자입니까? false } diff --git a/src/jeondabeen/report7/Report7_3.java b/src/jeondabeen/report7/Report7_3.java new file mode 100644 index 0000000..495fc66 --- /dev/null +++ b/src/jeondabeen/report7/Report7_3.java @@ -0,0 +1,60 @@ +package jeondabeen.report7; + +class MyTv { + boolean isPowerOn; + int channel; + int volume; + final int MAX_VOLUME = 100; + final int MIN_VOLUME = 0; + final int MAX_CHANNEL = 100; + final int MIN_CHANNEL = 1; + void turnOnOff() { + // (1) isPowerOn의 값이 true면 false로, false면 true로 바꾼다. + isPowerOn = !isPowerOn; + } + void volumeUp() { + // (2) volume의 값이 MAX_VOLUME보다 작을 때만 값을 1 증가시킨다. + if (volume < MAX_VOLUME) volume++; + } + void volumeDown() { + // (3) volume의 값이 MIN_VOLUME보다 클 때만 값을 1 감소시킨다. + if (volume > MIN_VOLUME) volume--; + } + void channelUp() { + // (4) channel의 값을 1 증가시킨다. + // 만일 channel이 MAX_CHANNEL이면 , channel의 값을 MIN_CHANNEL로 바꾼다. + if (channel == MAX_CHANNEL) { + channel = MIN_CHANNEL; + return; + } + + channel++; + } + void channelDown() { + // (5) channel의 값을 1 감소시킨다 . + // 만일 channel이 MIN_CHANNEL이면, channel의 값을 MAX_CHANNEL로 바꾼다. + if (channel == MIN_CHANNEL) { + channel = MAX_CHANNEL; + return; + } + + channel--; + } +} + +public class Report7_3 { + public static void main(String args[]) { + MyTv t = new MyTv(); + t.channel = 100; + t.volume = 0; + System.out.println("CH:" + t.channel + ", VOL:" + t.volume); + t.channelDown(); + t.volumeDown(); + System.out.println("CH:" + t.channel + ", VOL:" + t.volume); + t.volume = 100; + t.channelUp(); + t.volumeUp(); + System.out.println("CH:" + t.channel + ", VOL:" + t.volume); + } + //예상 결과 : CH: 100, VOL: 0 / CH: 99, VOL: 0 / CH: 100, VOL: 100 +} diff --git a/src/jeondabeen/report7/Report7_4.java b/src/jeondabeen/report7/Report7_4.java new file mode 100644 index 0000000..0972644 --- /dev/null +++ b/src/jeondabeen/report7/Report7_4.java @@ -0,0 +1,24 @@ +package jeondabeen.report7; + +public class Report7_4 { + static int max(int[] arr) { + int result = 0; + + if (arr == null || arr.length == 0) return -999999; + + for (int num : arr) { + if (num > result) result = num; + } + + return result; + } + + public static void main(String[] args) { + int[] data = {3,2,9,4,7}; + System.out.println(java.util.Arrays.toString(data)); + System.out.println("최대값 :"+max(data)); + System.out.println("최대값 :"+max(null)); + System.out.println("최대값 :"+max(new int[]{})); // 크기가 0인 배열 } + } + //예상 결과 : 최대값: 9 / 최대값: -99999 최대값: -999999 +} diff --git a/src/jeondabeen/report7/Report7_5.java b/src/jeondabeen/report7/Report7_5.java new file mode 100644 index 0000000..29b4e48 --- /dev/null +++ b/src/jeondabeen/report7/Report7_5.java @@ -0,0 +1,17 @@ +package jeondabeen.report7; + +public class Report7_5 { + static int abs(int value) { + if (value < 0) value *= -1; + + return value; + } + + public static void main(String[] args) { + int value = 5; + System.out.println(value + "의 절대값 :" + abs(value)); + value = -10; + System.out.println(value + "의 절대값 :" + abs(value)); + } + //예상 결과 : 5의 절대값 : 5 / -10의 절대값 : 10 +} From 7e0c5eb7ac575f5ea9c375b7bd61ed71624cbd92 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 25 Jan 2023 20:40:41 +0900 Subject: [PATCH 8/8] add: report8 --- src/jeondabeen/report8/Report8_1.java | 54 +++++++++++++++++ src/jeondabeen/report8/Report8_2.java | 86 +++++++++++++++++++++++++++ src/jeondabeen/report8/Report8_3.java | 34 +++++++++++ src/jeondabeen/report8/Report8_4.java | 50 ++++++++++++++++ src/jeondabeen/report8/Report8_5.java | 63 ++++++++++++++++++++ 5 files changed, 287 insertions(+) create mode 100644 src/jeondabeen/report8/Report8_1.java create mode 100644 src/jeondabeen/report8/Report8_2.java create mode 100644 src/jeondabeen/report8/Report8_3.java create mode 100644 src/jeondabeen/report8/Report8_4.java create mode 100644 src/jeondabeen/report8/Report8_5.java diff --git a/src/jeondabeen/report8/Report8_1.java b/src/jeondabeen/report8/Report8_1.java new file mode 100644 index 0000000..5b5597a --- /dev/null +++ b/src/jeondabeen/report8/Report8_1.java @@ -0,0 +1,54 @@ +package jeondabeen.report8; + +class SutdaDeck { + final int CARD_NUM = 20; + SutdaCard[] cards = new SutdaCard[CARD_NUM]; + + SutdaDeck() { + // (구현) 배열 SutdaCard를 적절히 초기화 하시오. + for (int i = 0; i < cards.length; i++) { + if (i >= 10) { + boolean isKwang = false; + + if (i == 10 || i == 12 || i == 17) isKwang = !(cards[i - 10].isKwang); + + cards[i] = new SutdaCard(i + 1 - 10, isKwang); + } else { + boolean isKwang = false; + + if (i == 0 || i == 2 || i == 7) isKwang = (int) (Math.random() * 2) != 0; + + cards[i] = new SutdaCard(i + 1, isKwang); + } + } + } +} + +class SutdaCard { + int num; + boolean isKwang; + + SutdaCard() { + this(1, true); + } + + SutdaCard(int num, boolean isKwang) { + this.num = num; + this.isKwang = isKwang; + } + + // info()대신 Object클래스의 toString()을 오버라이딩했다. + public String toString() { + return num + ( isKwang ? "K":""); + } +} + +class Report8_1 { + public static void main(String args[]) { + SutdaDeck deck = new SutdaDeck(); + + for (int i = 0; i < deck.cards.length; i++) + System.out.print(deck.cards[i] + ","); + } +} +// 예상결과) 1K,2,3K,4,5,6,7,8K,9,10,1,2,3,4,5,6,7,8,9,10, diff --git a/src/jeondabeen/report8/Report8_2.java b/src/jeondabeen/report8/Report8_2.java new file mode 100644 index 0000000..7806d8f --- /dev/null +++ b/src/jeondabeen/report8/Report8_2.java @@ -0,0 +1,86 @@ +package jeondabeen.report8; + +class SutdaDeck2 { + final int CARD_NUM = 20; + SutdaCard2[] cards = new SutdaCard2[CARD_NUM]; + + SutdaDeck2() { + for (int i = 0; i < cards.length; i++) { + if (i >= 10) { + boolean isKwang = false; + + if (i == 10 || i == 12 || i == 17) isKwang = !(cards[i - 10].isKwang); + + cards[i] = new SutdaCard2(i + 1 - 10, isKwang); + } else { + boolean isKwang = false; + + if (i == 0 || i == 2 || i == 7) isKwang = (int) (Math.random() * 2) != 0; + + cards[i] = new SutdaCard2(i + 1, isKwang); + } + } + } + + void shuffle() { + // (구현) + for (int i = 0; i < cards.length; i++) { + int j = (int) (Math.random() * cards.length); + + SutdaCard2 tmp = new SutdaCard2(); + tmp = cards[i]; + cards[i] = cards[j]; + cards[j] = tmp; + } + } + + SutdaCard2 pick(int index) { + // (구현) + return cards[index]; + } + + SutdaCard2 pick() { + // (구현) + int index = (int) (Math.random() * cards.length); + return cards[index]; + } +} // SutdaDeck + +class SutdaCard2 { + int num; + boolean isKwang; + + SutdaCard2() { + this(1, true); + } + + SutdaCard2(int num, boolean isKwang) { + this.num = num; + this.isKwang = isKwang; + } + + public String toString() { + return num + ( isKwang ? "K":""); + } +} + +class Report8_2 { + public static void main(String args[]) { + SutdaDeck2 deck = new SutdaDeck2(); + + System.out.println(deck.pick(0)); + System.out.println(deck.pick()); + deck.shuffle(); + + for(int i=0; i < deck.cards.length;i++) + System.out.print(deck.cards[i]+","); + + System.out.println(); + System.out.println(deck.pick(0)); + } +} +//예상결과) +// 1K +// 7 +// 2,6,10,1K,7,3,10,5,7,8,5,1,2,9,6,9,4,8K,4,3K, +// 2 diff --git a/src/jeondabeen/report8/Report8_3.java b/src/jeondabeen/report8/Report8_3.java new file mode 100644 index 0000000..fec5a15 --- /dev/null +++ b/src/jeondabeen/report8/Report8_3.java @@ -0,0 +1,34 @@ +package jeondabeen.report8; + +class Product { + int price; // 제품의 가격 + int bonusPoint; // 제품구매 시 제공하는 보너스점수 + + // (구현) + Product() { + } + + Product(int price) { + this.price = price; + bonusPoint = (int) (price / 10.0); + } +} + +class Tv extends Product { + Tv() { + // 자식 클래스 생성자에 부모 생성자 호출이 되어있지 않다면 + // 컴파일러가 자동으로 super()를 맨 윗 줄에 추가해주는데 + // 부모의 기본 생성자가 없고 매개변수를 필요로 하는 생성자만 존재해 + // 인자를 넘겨주지 못해 발생하는 Error다! + } + + public String toString() { + return "Tv"; + } +} + +class Report8_3 { + public static void main(String[] args) { + Tv t = new Tv(); + } +} diff --git a/src/jeondabeen/report8/Report8_4.java b/src/jeondabeen/report8/Report8_4.java new file mode 100644 index 0000000..75467ef --- /dev/null +++ b/src/jeondabeen/report8/Report8_4.java @@ -0,0 +1,50 @@ +package jeondabeen.report8; + +class MyTv { + private boolean isPowerOn; + private int channel; + private int volume; + + final int MAX_VOLUME = 100; + final int MIN_VOLUME = 0; + final int MAX_CHANNEL = 100; + final int MIN_CHANNEL = 1; + + // (구현) + + public boolean isPowerOn() { + return isPowerOn; + } + + public void setPowerOn(boolean isPowerOn) { + this.isPowerOn = isPowerOn; + } + + public int getChannel() { + return channel; + } + + public void setChannel(int channel) { + this.channel = channel; + } + + public int getVolume() { + return volume; + } + + public void setVolume(int volume) { + this.volume = volume; + } +} + +class Report8_4 { + public static void main(String args[]) { + MyTv t = new MyTv(); + + t.setChannel(10); + System.out.println("CH:" + t.getChannel()); + t.setVolume(20); + System.out.println("VOL:" + t.getVolume()); + } +} +//예상결과) CH:10 VOL:20 diff --git a/src/jeondabeen/report8/Report8_5.java b/src/jeondabeen/report8/Report8_5.java new file mode 100644 index 0000000..81bdf83 --- /dev/null +++ b/src/jeondabeen/report8/Report8_5.java @@ -0,0 +1,63 @@ +package jeondabeen.report8; + +class MyTv2 { + private boolean isPowerOn; + private int channel; + private int volume; + private int prevChannel; + // (구현) + + final int MAX_VOLUME = 100; + final int MIN_VOLUME = 0; + final int MAX_CHANNEL = 100; + final int MIN_CHANNEL = 1; + + public void setVolume(int volume) { + if (volume > MAX_VOLUME || volume < MIN_VOLUME) + return; + this.volume = volume; + } + + public int getVolume() { + return volume; + } + + public void setChannel(int channel) { + if (channel > MAX_CHANNEL || channel < MIN_CHANNEL) + return; + + // (구현) + prevChannel = this.channel; + this.channel = channel; + } + + public int getChannel() { + return channel; + } + + // (구현) + public void gotoPrevChannel() { + int tmp = channel; + channel = prevChannel; + prevChannel = tmp; + } +} + +class Report8_5 { + public static void main(String args[]) { + MyTv2 t = new MyTv2(); + t.setChannel(10); + System.out.println("CH:" + t.getChannel()); + t.setChannel(20); + System.out.println("CH:" + t.getChannel()); + t.gotoPrevChannel(); + System.out.println("CH:" + t.getChannel()); + t.gotoPrevChannel(); + System.out.println("CH:" + t.getChannel()); + } +} + +// CH:10 +// CH:20 +// CH:10 +// CH:20