From dad571ede5cc10e69ae01f00c923413c948daaa8 Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:32:35 +0900 Subject: [PATCH 01/13] solved:Chapter3-1 --- .../java/Practice/stopmin/Coffeetype.java | 15 +++++++++ .../java/Practice/stopmin/FinalPractice.java | 14 +++++++++ .../java/Practice/stopmin/HelloWorld.java | 13 ++++++++ .../java/Practice/stopmin/ListPractice.java | 21 +++++++++++++ .../java/Practice/stopmin/NumberPractice.java | 15 +++++++++ src/main/java/Practice/stopmin/Sample.java | 31 +++++++++++++++++++ .../java/Practice/stopmin/StringPractice.java | 26 ++++++++++++++++ .../java/Problem/stopmin/Chapter3/Q01.java | 4 ++- src/main/java/Save/Chapter3/Q01.java | 1 + src/main/java/Save/Chapter3/Q03.java | 1 + 10 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Practice/stopmin/Coffeetype.java create mode 100644 src/main/java/Practice/stopmin/FinalPractice.java create mode 100644 src/main/java/Practice/stopmin/HelloWorld.java create mode 100644 src/main/java/Practice/stopmin/ListPractice.java create mode 100644 src/main/java/Practice/stopmin/NumberPractice.java create mode 100644 src/main/java/Practice/stopmin/Sample.java create mode 100644 src/main/java/Practice/stopmin/StringPractice.java diff --git a/src/main/java/Practice/stopmin/Coffeetype.java b/src/main/java/Practice/stopmin/Coffeetype.java new file mode 100644 index 0000000..ae7727b --- /dev/null +++ b/src/main/java/Practice/stopmin/Coffeetype.java @@ -0,0 +1,15 @@ +package Practice.stopmin; + +public enum Coffeetype { + AMERICANO, + ICE_AMERICANO, + CAFE_LATTE; + public static void main(String[] args) { + System.out.println(AMERICANO); + for (Coffeetype type : Coffeetype.values()) { + System.out.println(type); + } + } +}; + + diff --git a/src/main/java/Practice/stopmin/FinalPractice.java b/src/main/java/Practice/stopmin/FinalPractice.java new file mode 100644 index 0000000..8e1aeed --- /dev/null +++ b/src/main/java/Practice/stopmin/FinalPractice.java @@ -0,0 +1,14 @@ +package Practice.stopmin; + +import java.util.ArrayList; + +public class FinalPractice { + + public static void main(String[] args) { + final int n = 10; + + final ArrayList a = new ArrayList<>(); + + a.add("hello~"); + } +} diff --git a/src/main/java/Practice/stopmin/HelloWorld.java b/src/main/java/Practice/stopmin/HelloWorld.java new file mode 100644 index 0000000..f6c9e72 --- /dev/null +++ b/src/main/java/Practice/stopmin/HelloWorld.java @@ -0,0 +1,13 @@ +package Practice.stopmin; + +public class HelloWorld { + + public static void main(String[] args) { + System.out.println("Hello World!"); // 표준 출력 + System.err.println("Error!"); // 표준 에러 출력 + System.out.println("숫자" + 3 + "~~~"); + + Sample sample = new Sample("EE"); + sample.myPublic(); + } +} diff --git a/src/main/java/Practice/stopmin/ListPractice.java b/src/main/java/Practice/stopmin/ListPractice.java new file mode 100644 index 0000000..5dd0609 --- /dev/null +++ b/src/main/java/Practice/stopmin/ListPractice.java @@ -0,0 +1,21 @@ +package Practice.stopmin; + +import java.util.ArrayList; +import java.util.Comparator; + +public class ListPractice { + + public static void main(String[] args) { + ArrayList pitches = new ArrayList(); + pitches.add("123"); + pitches.add("312"); + pitches.add("213"); + System.out.println(pitches); + + System.out.println("pitches.get(1) = " + pitches.get(1)); + System.out.println("pitches.size() = " + pitches.size()); + + pitches.sort(Comparator.naturalOrder()); + System.out.println(pitches); + } +} diff --git a/src/main/java/Practice/stopmin/NumberPractice.java b/src/main/java/Practice/stopmin/NumberPractice.java new file mode 100644 index 0000000..ce769fa --- /dev/null +++ b/src/main/java/Practice/stopmin/NumberPractice.java @@ -0,0 +1,15 @@ +package Practice.stopmin; + +public class NumberPractice { + + public static void main(String[] args) { + int age = 21; + long count = 102938901283012093L; + + age += 10; + + boolean isTest = true; // is~, has~, can~ + + } + +} diff --git a/src/main/java/Practice/stopmin/Sample.java b/src/main/java/Practice/stopmin/Sample.java new file mode 100644 index 0000000..d1f0ef7 --- /dev/null +++ b/src/main/java/Practice/stopmin/Sample.java @@ -0,0 +1,31 @@ +package Practice.stopmin; + +public class Sample { + + + private String message; // 속성, 필드 + + public Sample(String message) { + this.message = message; + } + + public static void main(String[] args) { + Sample sample = new Sample("ABDERERER"); + } + + public void myPublic() { + System.out.println(message); + } + + protected void myP() { + + } + + private void myP2() { + + } + + void myD() { + + } +} diff --git a/src/main/java/Practice/stopmin/StringPractice.java b/src/main/java/Practice/stopmin/StringPractice.java new file mode 100644 index 0000000..86b2f27 --- /dev/null +++ b/src/main/java/Practice/stopmin/StringPractice.java @@ -0,0 +1,26 @@ +package Practice.stopmin; + +public class StringPractice { + + public static void main(String[] args) { + String a = "Happy"; // 리터럴 방식 + String b = new String("Java"); // 객체 생성 + + System.out.println("a.eqauls(b) = " + a.equals(b)); + + boolean c = true; // 프리미티브 -> Null을 담을 수 없다. 대신 string은 안된다!! + Boolean e = true; // 레퍼클래스 + + e = null; + + int f = 10; + Integer g = 10; + + g = null; + + a.equals(b); + + // indexOf + // contains + } +} diff --git a/src/main/java/Problem/stopmin/Chapter3/Q01.java b/src/main/java/Problem/stopmin/Chapter3/Q01.java index ee0dce3..1246d8b 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q01.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q01.java @@ -10,6 +10,8 @@ public static void main(String[] args) { int english = 75; int math = 55; - // TODO: 평균 점수를 구해서 출력하기 +// TODO: 평균 점수를 구해서 출력하기 + System.out.println((korean + english + math) / 3); + } } diff --git a/src/main/java/Save/Chapter3/Q01.java b/src/main/java/Save/Chapter3/Q01.java index d6d58e7..9ac77dd 100644 --- a/src/main/java/Save/Chapter3/Q01.java +++ b/src/main/java/Save/Chapter3/Q01.java @@ -11,5 +11,6 @@ public static void main(String[] args) { int math = 55; // TODO: 평균 점수를 구해서 출력하기 + System.out.println((korean + english + math) / 3); } } diff --git a/src/main/java/Save/Chapter3/Q03.java b/src/main/java/Save/Chapter3/Q03.java index ce82b4c..7229646 100644 --- a/src/main/java/Save/Chapter3/Q03.java +++ b/src/main/java/Save/Chapter3/Q03.java @@ -9,5 +9,6 @@ public static void main(String[] args) { String personNumber = "881120-1068234"; // TODO: 주민등록번호를 연월일(YYYYMMDD) 부분과 그 뒤의 숫자 부분으로 나누어 출력하기 + System.out.println(personNumber.substring(0, 6) + "\n" + personNumber.substring(8, 14)); } } From da0b25032b22b6e7853f5db49649db00af11c291 Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:35:16 +0900 Subject: [PATCH 02/13] solved:Chapter3-2 --- src/main/java/Problem/stopmin/Chapter3/Q02.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q02.java b/src/main/java/Problem/stopmin/Chapter3/Q02.java index f03f4ff..8f4e9a0 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q02.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q02.java @@ -5,9 +5,21 @@ public class Q02 { /** * 홀수 짝수 판별 */ + public static boolean isOdd(int a) { + if (a % 2 == 1) { + return true; + } else { + return false; + } + } + public static void main(String[] args) { int num = 13; - // TODO: num이 홀수라면 odd를, 짝수라면 even을 출력하기 + if (isOdd(num)) { + System.out.println("Odd"); + } else { + System.out.println("even"); + } } } From cc660708a59a58398e7280d6ce6e22247ac16cb2 Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:36:31 +0900 Subject: [PATCH 03/13] solved:Chapter3-3 --- src/main/java/Problem/stopmin/Chapter3/Q03.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q03.java b/src/main/java/Problem/stopmin/Chapter3/Q03.java index c4f33c7..a66578f 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q03.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q03.java @@ -9,5 +9,7 @@ public static void main(String[] args) { String personNumber = "881120-1068234"; // TODO: 주민등록번호를 연월일(YYYYMMDD) 부분과 그 뒤의 숫자 부분으로 나누어 출력하기 + System.out.println(personNumber.substring(0, 6)); + System.out.println(personNumber.substring(7, 14)); } } From 6a0d992996ff264af1d442c6a525b08eb3f22a7b Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:38:34 +0900 Subject: [PATCH 04/13] solved:Chapter3-4 --- src/main/java/Problem/stopmin/Chapter3/Q05.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q05.java b/src/main/java/Problem/stopmin/Chapter3/Q05.java index 102f88a..0fb8bb7 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q05.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q05.java @@ -9,5 +9,7 @@ public static void main(String[] args) { String a = "a:b:c:d"; // TODO: replace 함수를 사용하여 a#b#c#d로 바꿔서 출력해 보자. + a = a.replaceAll(":", "#"); + System.out.println(a); } } From f332317dde1f5d917422343089eb8cfd477efe8a Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:42:12 +0900 Subject: [PATCH 05/13] solved:Chapter3-6 --- src/main/java/Problem/stopmin/Chapter3/Q06.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q06.java b/src/main/java/Problem/stopmin/Chapter3/Q06.java index 23748ec..af8d5ce 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q06.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q06.java @@ -2,6 +2,8 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; public class Q06 { @@ -13,5 +15,7 @@ public static void main(String[] args) { System.out.println(myList); // [1, 3, 5, 4, 2]가 출력됨. // TODO: 리스트를 [5, 4, 3, 2, 1]로 만들어서 출력하기 + Collections.sort(myList, Collections.reverseOrder()); + System.out.println(myList); } } From b7eb57f89407b5d071946ab663f07685fed172ad Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:44:10 +0900 Subject: [PATCH 06/13] solved:Chapter3-7 --- src/main/java/Problem/stopmin/Chapter3/Q07.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q07.java b/src/main/java/Problem/stopmin/Chapter3/Q07.java index b66f996..02395e5 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q07.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q07.java @@ -13,5 +13,7 @@ public static void main(String[] args) { System.out.println(myList); // [Life, is, too, short] 출력됨. // TODO: 리스트를 "Life is too short" 문자열로 만들어 출력해 보자. + String string = String.join(" ", myList); + System.out.println(string); } } From fb0c8378e8155c4e2f861a5a9d3d7ee6484c8692 Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:47:35 +0900 Subject: [PATCH 07/13] solved:Chapter3-8 --- src/main/java/Problem/stopmin/Chapter3/Q08.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q08.java b/src/main/java/Problem/stopmin/Chapter3/Q08.java index e457e8e..6cb3ceb 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q08.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q08.java @@ -1,6 +1,7 @@ package Problem.stopmin.Chapter3; import java.util.HashMap; +import java.util.Map; public class Q08 { @@ -14,5 +15,7 @@ public static void main(String[] args) { grade.put("C", 70); // TODO: 다음의 맵 grade에서 "B'에 해당되는 값을 추출해 보자. (추출하고 나면 grade에는 "B"에 해당하는 아이템이 사라져야 한다.) + grade.remove("B"); + System.out.println(grade); } } From 2a8bb454d9e114b55f0718be292c75c79b8b6fc0 Mon Sep 17 00:00:00 2001 From: stopmin Date: Fri, 7 Jul 2023 22:50:47 +0900 Subject: [PATCH 08/13] solved:Chapter3-9 --- src/main/java/Problem/stopmin/Chapter3/Q09.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q09.java b/src/main/java/Problem/stopmin/Chapter3/Q09.java index 793f4f2..9523a32 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q09.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q09.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.TreeSet; public class Q09 { @@ -13,5 +14,11 @@ public static void main(String[] args) { System.out.println(numbers); // [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5] 출력됨. // TODO: numbers 리스트에서 중복 숫자를 제거해 보자. + TreeSet treeSet = new TreeSet<>(); + for (Integer item : numbers) { + treeSet.add(item); + } + + System.out.println(treeSet); } } From 8907d5018dba0bfd4814c54216592ce75ef48100 Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 8 Jul 2023 00:28:34 +0900 Subject: [PATCH 09/13] solved:Chapter3-10 --- src/main/java/Problem/stopmin/Chapter3/Q10.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/Problem/stopmin/Chapter3/Q10.java b/src/main/java/Problem/stopmin/Chapter3/Q10.java index 9afb4e7..24c5eb2 100644 --- a/src/main/java/Problem/stopmin/Chapter3/Q10.java +++ b/src/main/java/Problem/stopmin/Chapter3/Q10.java @@ -12,8 +12,13 @@ static void printCoffeePrice(int type) { priceMap.put(1, 3000); // 1: 아메리카노 priceMap.put(2, 4000); // 2: 아이스 아메리카노 priceMap.put(3, 5000); // 3: 카페라떼 - int price = priceMap.get(type); - System.out.println(String.format("가격은 %d원 입니다.", price)); + Integer price = priceMap.get(type); + + if (price != null) { + System.out.println(String.format("가격은 %d원 입니다.", price)); + } else { + System.out.println("해당하는 커피 종류가 없습니다."); + } } public static void main(String[] args) { From 74791069540163805860d17a84608265d1c7b53b Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 8 Jul 2023 00:33:40 +0900 Subject: [PATCH 10/13] solved:Chapter4-1 --- src/main/java/Problem/stopmin/Chapter4/Q02.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter4/Q02.java b/src/main/java/Problem/stopmin/Chapter4/Q02.java index a471bc8..1fa306c 100644 --- a/src/main/java/Problem/stopmin/Chapter4/Q02.java +++ b/src/main/java/Problem/stopmin/Chapter4/Q02.java @@ -7,5 +7,16 @@ public class Q02 { */ public static void main(String[] args) { // TODO: while 문을 사용해서 1부터 1000까지의 자연수 중 3의 배수의 합을 구하기 + int num = 1; + int sum = 0; + + while (num < 1000) { + if (num % 3 == 0) { + sum += num; + } + num++; + } + + System.out.println(sum); } } From 2bb3f15a229aa78b9c5303c618b9f65bf09e4d26 Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 8 Jul 2023 00:35:42 +0900 Subject: [PATCH 11/13] solved:Chapter4-3 --- src/main/java/Problem/stopmin/Chapter4/Q03.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter4/Q03.java b/src/main/java/Problem/stopmin/Chapter4/Q03.java index d958601..026279a 100644 --- a/src/main/java/Problem/stopmin/Chapter4/Q03.java +++ b/src/main/java/Problem/stopmin/Chapter4/Q03.java @@ -13,5 +13,13 @@ public static void main(String[] args) { //*** //**** //***** + int num = 1; + while (num <= 5) { + for (int i = 0; i < num; i++) { + System.out.print("*"); + } + System.out.print("\n"); + num++; + } } } From af00ed9db0d7025596c294ec5c85bb5d381f9d80 Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 8 Jul 2023 00:36:27 +0900 Subject: [PATCH 12/13] solved:Chapter4-4 --- src/main/java/Problem/stopmin/Chapter4/Q04.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter4/Q04.java b/src/main/java/Problem/stopmin/Chapter4/Q04.java index 4fa3bbc..5e58082 100644 --- a/src/main/java/Problem/stopmin/Chapter4/Q04.java +++ b/src/main/java/Problem/stopmin/Chapter4/Q04.java @@ -7,5 +7,8 @@ public class Q04 { */ public static void main(String[] args) { // TODO: for문을 사용해 1부터 100까지의 숫자를 출력해 보자. + for (int i = 1; i <= 100; i++) { + System.out.println(i); + } } } From fc0eaa47e09e7c3c622f14e2149190a0e093f00e Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 8 Jul 2023 00:38:17 +0900 Subject: [PATCH 13/13] solved:Chapter4-5 --- src/main/java/Problem/stopmin/Chapter4/Q05.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Problem/stopmin/Chapter4/Q05.java b/src/main/java/Problem/stopmin/Chapter4/Q05.java index d3dfaf4..7ad3691 100644 --- a/src/main/java/Problem/stopmin/Chapter4/Q05.java +++ b/src/main/java/Problem/stopmin/Chapter4/Q05.java @@ -9,5 +9,11 @@ public static void main(String[] args) { int[] marks = {70, 60, 55, 75, 95, 90, 80, 80, 85, 100}; // TODO: for each 문을 사용하여 A 학급의 평균 점수를 구해 보자. + int average = 0; + + for (int entry : marks) { + average += entry; + } + System.out.println(average / marks.length); } }