From c9f52b584438c04db84b1d2554a04398c17b3371 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:33:47 +0800 Subject: [PATCH 01/33] Committed on or around 2025/02/01 --- Miscellaneous/Cpp/Array_of_objects_3.java | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Miscellaneous/Cpp/Array_of_objects_3.java diff --git a/Miscellaneous/Cpp/Array_of_objects_3.java b/Miscellaneous/Cpp/Array_of_objects_3.java new file mode 100644 index 0000000..f55fc88 --- /dev/null +++ b/Miscellaneous/Cpp/Array_of_objects_3.java @@ -0,0 +1,38 @@ +package Cpp; + +class MyClasses{ + private int x; + + void set_x(int i) { + x = i; + } + + int get_x() { + return x; + } +} + +public class Array_of_objects_3 { + + public static void main(String[] args) { + + + MyClasses[] objects = new MyClasses[4]; + + objects[0] = new MyClasses(); + objects[0].set_x(11); + + objects[1].set_x(22); + + objects[2].set_x(33); + + +// for (int i = 0; i < objects.length; i++) +// objects[i].set_x(i); + + for (int i = 0; i < objects.length; i++) + System.out.println("Objects[" + i + "].get_x(): " + objects[i].get_x()); + + } + +} From 6bd4b3d45ceb50383d8d1ce229d7b29792edac9a Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:34:54 +0800 Subject: [PATCH 02/33] Committed on or around 2025/02/01 --- Miscellaneous/Cpp/Array_of_objects_3.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Miscellaneous/Cpp/Array_of_objects_3.java b/Miscellaneous/Cpp/Array_of_objects_3.java index f55fc88..7ef0b9d 100644 --- a/Miscellaneous/Cpp/Array_of_objects_3.java +++ b/Miscellaneous/Cpp/Array_of_objects_3.java @@ -23,7 +23,6 @@ public static void main(String[] args) { objects[0].set_x(11); objects[1].set_x(22); - objects[2].set_x(33); From 504ec14cc7285d0b2bddbb586c08cf255ad2948a Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:37:24 +0800 Subject: [PATCH 03/33] Committed on or around 2025/02/01 --- Miscellaneous/Cpp/Array_of_objects_3.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Miscellaneous/Cpp/Array_of_objects_3.java b/Miscellaneous/Cpp/Array_of_objects_3.java index 7ef0b9d..aa1f547 100644 --- a/Miscellaneous/Cpp/Array_of_objects_3.java +++ b/Miscellaneous/Cpp/Array_of_objects_3.java @@ -15,16 +15,17 @@ int get_x() { public class Array_of_objects_3 { public static void main(String[] args) { - - + MyClasses[] objects = new MyClasses[4]; objects[0] = new MyClasses(); objects[0].set_x(11); - objects[1].set_x(22); - objects[2].set_x(33); - + objects[1] = new MyClasses(); + objects[1].set_x(99); + + objects[2].set_x(22); + objects[3].set_x(33); // for (int i = 0; i < objects.length; i++) // objects[i].set_x(i); From 637d666250259d2cb606604be692a6eada0aa0f8 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 18:08:12 +0800 Subject: [PATCH 04/33] Committed on or around 2025/02/01 --- Chapter7/Abstract_Class.java | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Chapter7/Abstract_Class.java diff --git a/Chapter7/Abstract_Class.java b/Chapter7/Abstract_Class.java new file mode 100644 index 0000000..e9d4cc6 --- /dev/null +++ b/Chapter7/Abstract_Class.java @@ -0,0 +1,78 @@ + +abstract class Abstract_TwoDShape { + + private double width; + private double height; + private String name; + + // A default constructor + public Abstract_TwoDShape() { + width = height = 0.0; + name = "none"; + } + + // Parameterized constructor. + Abstract_TwoDShape(double w, double h, String n){ + width = w; + height = h; + name = n; + } + + // Construct object with equal width and height. + Abstract_TwoDShape(double x, String n){ + width = height = x; + name = n; + } + + // Construct an object from an object. + Abstract_TwoDShape(Abstract_TwoDShape ob){ + width = ob.width; + height = ob.height; + name = ob.name; + } + + // Accessor methods for width and height. + double getWidth() { + return width; + } + + double getHeight() { + return height; + } + + void setWidth(double w) { + width = w; + } + + void setHeight(double h) { + height = h; + } + + String getName() { + return name; + } + + void showDim() { + System.out.println("Width and height are " + width + " and " + height); + } + + // declare an abstract method + abstract double area(); + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} + + + +public class Abstract_Class { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From d2df6aa4515aaa8ac7c097c6047fb3f73d462520 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 18:12:10 +0800 Subject: [PATCH 05/33] Committed on or around 2025/02/01 --- Chapter7/Abstract_Class.java | 45 ++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/Chapter7/Abstract_Class.java b/Chapter7/Abstract_Class.java index e9d4cc6..f6af48e 100644 --- a/Chapter7/Abstract_Class.java +++ b/Chapter7/Abstract_Class.java @@ -59,15 +59,52 @@ void showDim() { // declare an abstract method abstract double area(); - public static void main(String[] args) { - // TODO Auto-generated method stub +} - } +class Triangle_extends_abstract_superclass2 extends Abstract_TwoDShape { + + private String styleString; + + // A default constructor + public Triangle_extends_abstract_superclass2() { + // TODO Auto-generated constructor stub + super(); + + styleString = "none"; + + } + + // Constructor for Triangle + Triangle_extends_abstract_superclass2(String s, double w, double h){ + super(w, h, "triangle"); + + styleString = s; + } + + // One argument constructor. + Triangle_extends_abstract_superclass2(double x){ + super(x, "triangle"); // call superclass constructor + + styleString = "filled"; + } + + // Construct an object from an object. + Triangle_extends_abstract_superclass2(Triangle_extends_abstract_superclass ob){ + super(ob); // pass object to TwoDShape constructor + styleString = ob.styleString; + } + + double area() { + return getWidth() * getHeight() / 2; + } + + void showStyle() { + System.out.println("Triangle is " + styleString); + } } - public class Abstract_Class { public static void main(String[] args) { From fcb3e4956e433ce812c9cdab04b31538d0af8654 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 18:17:13 +0800 Subject: [PATCH 06/33] Committed on or around 2025/02/01 --- Chapter7/Abstract_Class.java | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/Chapter7/Abstract_Class.java b/Chapter7/Abstract_Class.java index f6af48e..0c329a3 100644 --- a/Chapter7/Abstract_Class.java +++ b/Chapter7/Abstract_Class.java @@ -90,7 +90,7 @@ public Triangle_extends_abstract_superclass2() { } // Construct an object from an object. - Triangle_extends_abstract_superclass2(Triangle_extends_abstract_superclass ob){ + Triangle_extends_abstract_superclass2(Triangle_extends_abstract_superclass2 ob){ super(ob); // pass object to TwoDShape constructor styleString = ob.styleString; } @@ -105,10 +105,60 @@ void showStyle() { } +class Rectangle_extends_abstract_superclass2 extends Abstract_TwoDShape { + + // A default constructor + public Rectangle_extends_abstract_superclass2() { + // TODO Auto-generated constructor stub + super(); + } + + // Constructor for Rectangle + Rectangle_extends_abstract_superclass2(double w, double h){ + super(w, h, "rectangle"); // Call superclass constructor + } + + // Construct a square + Rectangle_extends_abstract_superclass2(double x) { + super(x, "rectangle"); // call superclass constructor + } + + // Construct an object from an object. + Rectangle_extends_abstract_superclass2(Rectangle_extends_abstract_superclass ob){ + super(ob); // pass object to TwoDShape constructor. + } + + boolean isSquare() { + + if ( getWidth() == getHeight() ) + return true; + + return false; + } + + double area() { + return getWidth() * getHeight(); + } + +} + public class Abstract_Class { public static void main(String[] args) { - // TODO Auto-generated method stub + + Abstract_TwoDShape shapes[] = new Abstract_TwoDShape[4]; + + shapes[0] = new Triangle_extends_abstract_superclass2("outlined", 8.0, 12.0); + shapes[1] = new Rectangle_extends_abstract_superclass2(10); + shapes[2] = new Rectangle_extends_abstract_superclass2(10, 4); + shapes[3] = new Triangle_extends_abstract_superclass2(7.0); + + for (int i = 0; i < shapes.length; i++) { + System.out.println("Object is " + shapes[i].getName()); + System.out.println("Area is " + shapes[i].area()); + + System.out.println(); + } } From 60a95db1bf78060ee7f770d6ac453a2e6599f44c Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 1 Feb 2025 18:17:40 +0800 Subject: [PATCH 07/33] Committed on or around 2025/02/01 --- Chapter7/Abstract_Class.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter7/Abstract_Class.java b/Chapter7/Abstract_Class.java index 0c329a3..11a8783 100644 --- a/Chapter7/Abstract_Class.java +++ b/Chapter7/Abstract_Class.java @@ -124,7 +124,7 @@ public Rectangle_extends_abstract_superclass2() { } // Construct an object from an object. - Rectangle_extends_abstract_superclass2(Rectangle_extends_abstract_superclass ob){ + Rectangle_extends_abstract_superclass2(Rectangle_extends_abstract_superclass2 ob){ super(ob); // pass object to TwoDShape constructor. } From 7ca224008e6c9799de035eb0818a1a782f2edc83 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 14:00:22 +0800 Subject: [PATCH 08/33] Committed on or around 2025/05/27 --- .../C/Uninitialized_array_element_content.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Miscellaneous/C/Uninitialized_array_element_content.java diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java new file mode 100644 index 0000000..b032f0f --- /dev/null +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -0,0 +1,13 @@ +package C; + +public class Uninitialized_array_element_content { + + public static void main(String[] args) { + + final int ALL_INPUT_LINES_LONGER_THAN_EIGHTY = 500; + + char more_than_80_characters[] = new char[ALL_INPUT_LINES_LONGER_THAN_EIGHTY]; + + } + +} From b94649a14d2bb6d09459f438a683ea89e43311ce Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 14:11:46 +0800 Subject: [PATCH 09/33] Committed on or around 2025/05/27 --- Miscellaneous/C/Uninitialized_array_element_content.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java index b032f0f..7f8213a 100644 --- a/Miscellaneous/C/Uninitialized_array_element_content.java +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -7,6 +7,13 @@ public static void main(String[] args) { final int ALL_INPUT_LINES_LONGER_THAN_EIGHTY = 500; char more_than_80_characters[] = new char[ALL_INPUT_LINES_LONGER_THAN_EIGHTY]; + + if(more_than_80_characters[0] == 0) + System.out.println("more_than_80_characters[0] is 0\n"); + else + + System.out.println("more_than_80_characters[0] is " + more_than_80_characters[0]); + } From 7a8c58eff5229f8c0edcba360966ed591911161b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 14:13:00 +0800 Subject: [PATCH 10/33] Committed on or around 2025/05/27 --- Miscellaneous/C/Uninitialized_array_element_content.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java index 7f8213a..c3ecf32 100644 --- a/Miscellaneous/C/Uninitialized_array_element_content.java +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -9,7 +9,7 @@ public static void main(String[] args) { char more_than_80_characters[] = new char[ALL_INPUT_LINES_LONGER_THAN_EIGHTY]; if(more_than_80_characters[0] == 0) - System.out.println("more_than_80_characters[0] is 0\n"); + System.out.println("more_than_80_characters[0] is 0"); else System.out.println("more_than_80_characters[0] is " + more_than_80_characters[0]); From bf8ed5a80395d49e614195b5b98dc8a34d68bb6f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 14:27:17 +0800 Subject: [PATCH 11/33] Committed on or around 2025/05/27 --- Miscellaneous/C/Uninitialized_array_element_content.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java index c3ecf32..2905e86 100644 --- a/Miscellaneous/C/Uninitialized_array_element_content.java +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -9,10 +9,10 @@ public static void main(String[] args) { char more_than_80_characters[] = new char[ALL_INPUT_LINES_LONGER_THAN_EIGHTY]; if(more_than_80_characters[0] == 0) - System.out.println("more_than_80_characters[0] is 0"); + System.out.println("Look! more_than_80_characters[0] is 0"); else - System.out.println("more_than_80_characters[0] is " + more_than_80_characters[0]); + System.out.println("See! more_than_80_characters[0] is " + more_than_80_characters[0]); } From ab76f9d45af23a1017013be5504611d9cb64fd00 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 14:55:53 +0800 Subject: [PATCH 12/33] Committed on or around 2025/05/27 --- Miscellaneous/C/Uninitialized_array_element_content.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java index 2905e86..112d943 100644 --- a/Miscellaneous/C/Uninitialized_array_element_content.java +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -18,3 +18,5 @@ public static void main(String[] args) { } } + +// Adapted from https://github.com/ResilientSpring/The-C-Programming-Language/blob/main/Blend/Uninitialized%20array%20element's%20content%202/bruise%203.c \ No newline at end of file From 51670140d633241d0495a32cb33632c6fe8e075b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 27 May 2025 17:36:48 +0800 Subject: [PATCH 13/33] Committed on or around 2025/05/27 --- Miscellaneous/C/Uninitialized_array_element_content.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Miscellaneous/C/Uninitialized_array_element_content.java b/Miscellaneous/C/Uninitialized_array_element_content.java index 112d943..77b95ac 100644 --- a/Miscellaneous/C/Uninitialized_array_element_content.java +++ b/Miscellaneous/C/Uninitialized_array_element_content.java @@ -19,4 +19,6 @@ public static void main(String[] args) { } -// Adapted from https://github.com/ResilientSpring/The-C-Programming-Language/blob/main/Blend/Uninitialized%20array%20element's%20content%202/bruise%203.c \ No newline at end of file +// Adapted from https://github.com/ResilientSpring/The-C-Programming-Language/blob/main/Blend/Uninitialized%20array%20element's%20content%202/bruise%203.c + +// Important Note: https://chatgpt.com/c/68349761-6ad8-8008-8673-728152e81f3a \ No newline at end of file From 92a1ccdaf1a4b6801673b4f769156623a2ff5c51 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:07:50 +0800 Subject: [PATCH 14/33] Committed on or around 2025/07/06 --- .../Programming_No1.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1.java new file mode 100644 index 0000000..3f924be --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1.java @@ -0,0 +1,27 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Programming_No1 { + + long Catalan_Number(int n) { + + long sum; + + if(n == 0) + return 1; + + for (int i = 0; i < n; i++) { + + + + } + + return sum; + + } + + public static void main(String[] args) { + + + } + +} From 11452347ff7056e75d8e8690073e4f812bc00b4e Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:32:10 +0800 Subject: [PATCH 15/33] Committed on or around 2025/07/06 --- .../Programming_No1_2.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java new file mode 100644 index 0000000..763daa6 --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java @@ -0,0 +1,34 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Programming_No1_2 { + + long Catalan_Number(int n) { + + long sum; + + if(n == 0) { + + sum = 1; + + return sum; + + } + + + for (int i = 0; i < n; i++) { + + + + } + + return sum; + + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 0a4d2671462abe44b47522ac7f58834b08f8884d Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:36:08 +0800 Subject: [PATCH 16/33] Committed on or around 2025/07/06 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_2.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java index 763daa6..033484f 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java @@ -17,7 +17,7 @@ long Catalan_Number(int n) { for (int i = 0; i < n; i++) { - + sum = Catalan_Number(i) * Catalan_Number(n-1-i); } @@ -27,7 +27,7 @@ long Catalan_Number(int n) { public static void main(String[] args) { - // TODO Auto-generated method stub + } From 3577b5be7a39895cdbf476bc124b07c286f69f1b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:38:16 +0800 Subject: [PATCH 17/33] Committed on or around 2025/07/06 --- .../Programming_No1_2.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java index 033484f..28e9b8a 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java @@ -3,31 +3,28 @@ public class Programming_No1_2 { long Catalan_Number(int n) { - + long sum; - - if(n == 0) { - + + if (n == 0) { + sum = 1; - + return sum; - + } - - + for (int i = 0; i < n; i++) { - - sum = Catalan_Number(i) * Catalan_Number(n-1-i); - + + sum = Catalan_Number(i) * Catalan_Number(n - 1 - i); + } - + return sum; - + } - - + public static void main(String[] args) { - } From f7cbc85ca73ae5f56e4739afcc10b16e2d64f4ef Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:49:56 +0800 Subject: [PATCH 18/33] Committed on or around 2025/07/06 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_2.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java index 28e9b8a..2fffd89 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_2.java @@ -1,8 +1,10 @@ package L4_Civil_Servant_Admission_Exam; +import Cpp.static_variable; + public class Programming_No1_2 { - long Catalan_Number(int n) { + long static Catalan_Number(int n) { long sum; @@ -26,6 +28,9 @@ long Catalan_Number(int n) { public static void main(String[] args) { + System.out.println(Catalan); + + } } From 4efbf3e3cb304ab61e3fc9a7c68647ca5abc8ac2 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:52:30 +0800 Subject: [PATCH 19/33] Committed on or around 2025/07/06 --- .../Programming_No1_3.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java new file mode 100644 index 0000000..5086efb --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java @@ -0,0 +1,32 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Programming_No1_3 { + + static long Catalan_Number(int n) { + + long sum; + + if (n == 0) { + + sum = 1; + + return sum; + + } + + for (int i = 0; i < n; i++) { + + sum = Catalan_Number(i) * Catalan_Number(n - 1 - i); + + } + + return sum; + + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 0543d0e78d1ace989b70d72c70dfa3eb9e395d14 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:53:06 +0800 Subject: [PATCH 20/33] Committed on or around 2025/07/06 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_3.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java index 5086efb..59c2748 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_3.java @@ -25,7 +25,7 @@ static long Catalan_Number(int n) { } public static void main(String[] args) { - // TODO Auto-generated method stub + } From 5402a4c60b6e21924cab1efb1b34e426cd07ed82 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:49:45 +0800 Subject: [PATCH 21/33] Committed on or around 2025/07/07 --- .../Programming_No1_4.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java new file mode 100644 index 0000000..7903b3e --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java @@ -0,0 +1,44 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Programming_No1_4 { + + static long Catalan_Number(int n) { + + // But Catalan_Number will call itself later, which might restart the sum from zero every time + // Catalan_Number is called and cause the intermediate result of the sum to be lost. + // + // Each call to Catalan_Number(n) has its own independent copy of the sum variable on the call stack. + // So even though sum is initialized to 0 every time the function is called, + // this happens in the scope of that one call only.[1] + long sum = 0; + + if (n == 0) { + + sum = 1; + + return sum; + + } + + for (int i = 0; i < n; i++) { + + sum = Catalan_Number(i) * Catalan_Number(n - 1 - i); + + } + + return sum; + + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} + +/* References: + * + * 1. https://chatgpt.com/c/6869ef92-f4c8-8008-b7b6-c9d0ee97820b + * + * */ From ec12fa9fb504d4232df35e03c6d037cfa7e80f73 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:50:26 +0800 Subject: [PATCH 22/33] Committed on or around 2025/07/07 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_4.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java index 7903b3e..e3e0087 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java @@ -31,7 +31,8 @@ static long Catalan_Number(int n) { } public static void main(String[] args) { - // TODO Auto-generated method stub + + } From 6db5c8fa130aab92fb77167112a6351446b3b927 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:51:30 +0800 Subject: [PATCH 23/33] Committed on or around 2025/07/07 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_4.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java index e3e0087..4a43b43 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_4.java @@ -32,7 +32,7 @@ static long Catalan_Number(int n) { public static void main(String[] args) { - + System.out.println(Catalan_Number(4)); } From 64df1769425a7ae8604219b77e1b425435738c1b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:00:27 +0800 Subject: [PATCH 24/33] Committed on or around 2025/07/07 --- .../Programming_No1_5.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java new file mode 100644 index 0000000..f12f7ae --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java @@ -0,0 +1,45 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Programming_No1_5 { + + static long Catalan_Number(int n) { + + // But Catalan_Number will call itself later, which might restart the sum from zero every time + // Catalan_Number is called and cause the intermediate result of the sum to be lost. + // + // Each call to Catalan_Number(n) has its own independent copy of the sum variable on the call stack. + // So even though sum is initialized to 0 every time the function is called, + // this happens in the scope of that one call only.[1] + long sum = 0; + + if (n == 0) { + + sum = 1; + + return sum; + + } + + for (int i = 0; i < n; i++) { + + sum = Catalan_Number(i) * Catalan_Number(n - 1 - i); + + } + + return sum; + + } + + public static void main(String[] args) { + + System.out.println(Catalan_Number(4)); + + } + +} + +/* References: + * + * 1. https://chatgpt.com/c/6869ef92-f4c8-8008-b7b6-c9d0ee97820b + * + * */ From c66d5b90b0a61d060b290b0c3eced61a1d974194 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:01:01 +0800 Subject: [PATCH 25/33] Committed on or around 2025/07/07 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java index f12f7ae..9f3e472 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java @@ -22,7 +22,7 @@ static long Catalan_Number(int n) { for (int i = 0; i < n; i++) { - sum = Catalan_Number(i) * Catalan_Number(n - 1 - i); + sum = sum + Catalan_Number(i) * Catalan_Number(n - 1 - i); } From 40a745395303409eb460d958ceac499dea3a3f00 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:07:16 +0800 Subject: [PATCH 26/33] Committed on or around 2025/07/07 --- .../L4_Civil_Servant_Admission_Exam/Programming_No1_5.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java index 9f3e472..d6a41b3 100644 --- a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Programming_No1_5.java @@ -22,6 +22,8 @@ static long Catalan_Number(int n) { for (int i = 0; i < n; i++) { + // Catalan Formula involves Sigma, so you must add all operands.[1] + // Sigma means to "add" all operands, rather than to "multiply" all operands.[1] sum = sum + Catalan_Number(i) * Catalan_Number(n - 1 - i); } From f6750f035ce1275a6ec1511fec9fbae2e0cd935f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 10 Nov 2025 23:58:17 +0800 Subject: [PATCH 27/33] Committed on or around 2025/11/10 --- Miscellaneous/SOE/HappyNumber.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Miscellaneous/SOE/HappyNumber.java diff --git a/Miscellaneous/SOE/HappyNumber.java b/Miscellaneous/SOE/HappyNumber.java new file mode 100644 index 0000000..154f990 --- /dev/null +++ b/Miscellaneous/SOE/HappyNumber.java @@ -0,0 +1,10 @@ +package SOE; + +public class HappyNumber { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 0f4d0ad2aef284e0bd09628133e24b7afcf195ce Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Tue, 11 Nov 2025 12:29:44 +0800 Subject: [PATCH 28/33] Committed on or around 2025/11/11 --- Miscellaneous/SOE/HappyNumber.java | 43 +++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/Miscellaneous/SOE/HappyNumber.java b/Miscellaneous/SOE/HappyNumber.java index 154f990..4507bc9 100644 --- a/Miscellaneous/SOE/HappyNumber.java +++ b/Miscellaneous/SOE/HappyNumber.java @@ -1,10 +1,47 @@ package SOE; +import java.util.HashSet; +import java.util.Set; + public class HappyNumber { - public static void main(String[] args) { - // TODO Auto-generated method stub + // 計算各位數平方和 + static int next(int n) { + int sum = 0; + while (n > 0) { + int d = n % 10; + sum += d * d; + n /= 10; + } + return sum; + } + + // 遞迴版 isHappy() + static boolean isHappy(int n) { + return isHappyHelper(n, new HashSet<>()); + } + + // 遞迴輔助函式:傳遞 seen 集合 + private static boolean isHappyHelper(int n, Set seen) { + if (n == 1) + return true; // 終止條件:快樂數 + if (seen.contains(n)) + return false; // 終止條件:進入循環 + + seen.add(n); + return isHappyHelper(next(n), seen); + } - } + // 測試 + public static void main(String[] args) { + int[] nums = {1, 7, 19, 20, 25, 4}; + for (int n : nums) { + System.out.printf("%d -> %s%n", n, isHappy(n)); + } + } } + +// Source: https://chatgpt.com/c/69104fa3-4828-8321-ade1-f983f1f8c14c + + From 68a61a0213e05ff3ca1fd3ff7e109c687ead7d80 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:06:37 +0800 Subject: [PATCH 29/33] Committed on or around 2026/04/19 --- .../Intro_to_CS_No17_2026.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java new file mode 100644 index 0000000..3ea27b6 --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java @@ -0,0 +1,29 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Intro_to_CS_No17_2026 { + + public static void main(String[] args) { + + int month = 1; + + while(month <= 4) { + + switch(month) { + + case 1: + System.out.println("31"); + + case 2: + System.out.println("28"); + + case 4: + System.out.println("30"); + + } + + month++; + } + + } + +} From 9c635208ecb38e4eb9387a0cf75d2f70d068513f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:22:07 +0800 Subject: [PATCH 30/33] Committed on 2025/06/11 --- Chapter7/SupSubRef2.java | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Chapter7/SupSubRef2.java diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java new file mode 100644 index 0000000..2e19ecc --- /dev/null +++ b/Chapter7/SupSubRef2.java @@ -0,0 +1,41 @@ +// A superclass reference can refer to a subclass object. + +class X3 { + int a; + + public X3(int i) { + // TODO Auto-generated constructor stub + + a = i; + } +} + +class Y3 extends X3 { + int b; + + public Y3(int i, int j) { + // TODO Auto-generated constructor stub + super(j); + b = i; + } +} + +public class SupSubRef2 { + + public static void main(String[] args) { + + X3 x = new X3(10); + Y3 y = new Y3(5, 6); + + System.out.println("X.a: " + x.a); + + x = y; + System.out.println("X.a: " + x.a); + + // X references know only about X members + x.a = 19; // OK +// x2.b = 27; // Error, X does not have a b member. + + } + +} From 129bb515c3813c1afd514c616516ab2c543bafef Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:26:55 +0800 Subject: [PATCH 31/33] Committed on or around 2026/06/11 --- Chapter7/SupSubRef2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java index 2e19ecc..ce10dac 100644 --- a/Chapter7/SupSubRef2.java +++ b/Chapter7/SupSubRef2.java @@ -34,7 +34,7 @@ public static void main(String[] args) { // X references know only about X members x.a = 19; // OK -// x2.b = 27; // Error, X does not have a b member. +// x.b = 27; // Error, X does not have a b member. } From f0837941c52bd708db12fa700a2545b8078901c7 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:37:57 +0800 Subject: [PATCH 32/33] Committed on 2026/06/11 --- Chapter7/Dynamic_Disptach_Demo_2.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Chapter7/Dynamic_Disptach_Demo_2.java diff --git a/Chapter7/Dynamic_Disptach_Demo_2.java b/Chapter7/Dynamic_Disptach_Demo_2.java new file mode 100644 index 0000000..318154e --- /dev/null +++ b/Chapter7/Dynamic_Disptach_Demo_2.java @@ -0,0 +1,24 @@ + +public class Dynamic_Disptach_Demo_2 { + + public static void main(String[] args) { + + Sup superOb = new Sup(); + Sub1 subOb1 = new Sub1(); + Sub2 subOb2 = new Sub2(); + + Sup supRef; // Declaring a variable called supRef of the class type Sup. This variable does not define an object. Instead, it is simply a variable that can refer to an object. + + supRef = superOb; + supRef.who(); // In each case, the version of who() to call is determined at run time by ... + + supRef = subOb1; + supRef.who(); // ... the type of object being referred to. + + supRef = subOb2; + supRef.who(); + + + } + +} From 98bd68093662581b3e24552686a1ab0b046dec80 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:52:58 +0800 Subject: [PATCH 33/33] Committed on or around 2026/06/11 --- Chapter7/Dynamic_Disptach_Demo_2.java | 15 +++++---------- Chapter7/SupSubRef2.java | 14 +++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Chapter7/Dynamic_Disptach_Demo_2.java b/Chapter7/Dynamic_Disptach_Demo_2.java index 318154e..9babea9 100644 --- a/Chapter7/Dynamic_Disptach_Demo_2.java +++ b/Chapter7/Dynamic_Disptach_Demo_2.java @@ -4,19 +4,14 @@ public class Dynamic_Disptach_Demo_2 { public static void main(String[] args) { Sup superOb = new Sup(); - Sub1 subOb1 = new Sub1(); - Sub2 subOb2 = new Sub2(); - Sup supRef; // Declaring a variable called supRef of the class type Sup. This variable does not define an object. Instead, it is simply a variable that can refer to an object. + superOb.who(); // In each case, the version of who() to call is determined at run time by ... - supRef = superOb; - supRef.who(); // In each case, the version of who() to call is determined at run time by ... + superOb = new Sub1(); + superOb.who(); // ... the type of object being referred to. - supRef = subOb1; - supRef.who(); // ... the type of object being referred to. - - supRef = subOb2; - supRef.who(); + superOb = new Sub2(); + superOb.who(); } diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java index ce10dac..3a9a0a3 100644 --- a/Chapter7/SupSubRef2.java +++ b/Chapter7/SupSubRef2.java @@ -24,17 +24,17 @@ public class SupSubRef2 { public static void main(String[] args) { - X3 x = new X3(10); - Y3 y = new Y3(5, 6); + X3 x3 = new X3(10); + Y3 y3 = new Y3(5, 6); - System.out.println("X.a: " + x.a); + System.out.println("X.a: " + x3.a); - x = y; - System.out.println("X.a: " + x.a); + x3 = y3; + System.out.println("X.a: " + x3.a); // X references know only about X members - x.a = 19; // OK -// x.b = 27; // Error, X does not have a b member. + x3.a = 19; // OK +// x3.b = 27; // Error, X does not have a b member. }