From 5052fecbffb86b3a973dd42f31f471beda3a0687 Mon Sep 17 00:00:00 2001 From: Kathryn Hodge Date: Sun, 23 Oct 2022 15:14:42 +0000 Subject: [PATCH 1/6] init challenge --- src/App.java | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/App.java b/src/App.java index 945d723..6aeeb19 100644 --- a/src/App.java +++ b/src/App.java @@ -1,6 +1,32 @@ public class App { - public static void main(String[] args) { - + public static Integer findSecondSmallestItem(Integer[] arr) { + return 0; } + + public static void main(String args[]) { + Integer[] arr = new Integer[]{ 5, 8, 3, 2, 6 }; + System.out.println(findSecondSmallestItem(arr)); + + Integer[] arr2 = new Integer[]{ 3, 8, 5, 2, 6 }; + System.out.println(findSecondSmallestItem(arr2)); + + Integer[] arr3 = new Integer[]{ 6, 8, 5, 2, 3 }; + System.out.println(findSecondSmallestItem(arr3)); + + Integer[] arr4 = new Integer[]{ 3, 3, 3, 3, 3 }; + System.out.println(findSecondSmallestItem(arr4)); + + Integer[] arr5 = new Integer[]{ 3, 3, 3, 2, 3 }; + System.out.println(findSecondSmallestItem(arr5)); + + Integer[] arr6 = new Integer[]{ 3, 4, 3, 3, 3 }; + System.out.println(findSecondSmallestItem(arr6)); + + Integer[] arrEmpty = new Integer[] {}; + System.out.println(findSecondSmallestItem(arrEmpty)); + + Integer[] arrOne = new Integer[] { 1 }; + System.out.println(findSecondSmallestItem(arrOne)); + } } \ No newline at end of file From 4e9c91c0d6148f7d7abb4da5d109f1f3af74ba95 Mon Sep 17 00:00:00 2001 From: smoser-LiL Date: Thu, 19 Jan 2023 22:52:26 +0000 Subject: [PATCH 2/6] Moving files using main --- NOTICE | 5 +---- README.md | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/NOTICE b/NOTICE index 547595f..6e2b44a 100644 --- a/NOTICE +++ b/NOTICE @@ -1,12 +1,9 @@ -Copyright 2022 LinkedIn Corporation +Copyright 2023 LinkedIn Corporation All Rights Reserved. Licensed under the LinkedIn Learning Exercise File License (the "License"). See LICENSE in the project root for license information. -ATTRIBUTIONS: -[PLEASE PROVIDE ATTRIBUTIONS OR DELETE THIS AND THE ABOVE LINE “ATTRIBUTIONS”] - Please note, this project may automatically load third party code from external repositories (for example, NPM modules, Composer packages, or other dependencies). If so, such third party code may be subject to other license terms than as set diff --git a/README.md b/README.md index a329521..d919760 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ -# Practice It! Java Arrays -This is the repository for the LinkedIn Learning course `Practice It! Java Arrays`. The full course is available from [LinkedIn Learning][lil-course-url]. +# Practice It: Java Arrays +This is the repository for the LinkedIn Learning course Practice It: Java Arrays. The full course is available from [LinkedIn Learning][lil-course-url]. + +![Practice It: Java Arrays][lil-thumbnail-url] + +Do you have experience using arrays in Java? Want to put your knowledge to the test or get more experience? If so, check out this course, as instructor Kathryn Hodge presents a series of challenges centered around real-world problems you might encounter and use arrays to solve. After a short review of the basics of how to work with the array data structure, Kathryn jumps into the challenges, testing your knowledge and abilities of looping through arrays, using the modulo operator with arrays, working with array indices, and more. If you’re looking to improve your command of Java arrays, get started on the path to mastery with these carefully chosen challenges and detailed solutions. + +This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace. Check out the “Using GitHub Codespaces with this course” video to learn how to get started. + -![course-name-alt-text][lil-thumbnail-url] -_See the readme file in the main branch for updated instructions and information._ ## Instructions This repository has branches for each of the videos in the course. You can use the branch pop up menu in github to switch to a specific branch and take a look at the course at that stage, or you can add `/tree/BRANCH_NAME` to the URL to go to the branch you want to access. @@ -22,15 +27,16 @@ To resolve this issue: Add changes to git using this command: git add . Commit changes using this command: git commit -m "some message" -## Installing -1. To use these exercise files, you must have the following installed: - - [list of requirements for course] -2. Clone this repository into your local machine using the terminal (Mac), CMD (Windows), or a GUI tool like SourceTree. -3. [Course-specific instructions] +### Instructor + +Kathryn Hodge + +Software Engineer -[0]: # (Replace these placeholder URLs with actual course URLs) + -[lil-course-url]: https://www.linkedin.com/learning/ -[lil-thumbnail-url]: http:// +Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/kathryn-hodge). +[lil-course-url]: https://www.linkedin.com/learning/practice-it-java-arrays?dApp=59033956 +[lil-thumbnail-url]: https://media.licdn.com/dms/image/C560DAQGxvknrUSCYyg/learning-public-crop_675_1200/0/1674065752872?e=2147483647&v=beta&t=alZ8uNljq1YU5rek0_VhuddFylQVKNSJVdDc7lQAa1k From f004d1a6147e778292183647611bfa3a1c52d0f3 Mon Sep 17 00:00:00 2001 From: pcstevens Date: Fri, 3 Mar 2023 23:52:31 +0000 Subject: [PATCH 3/6] Moving files using main --- .github/workflows/main.yml | 2 +- .vscode/settings.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e71e597..a648faf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,6 @@ jobs: with: fetch-depth: 0 - name: Copy To Branches Action - uses: planetoftheweb/copy-to-branches@v1.2 + uses: smoser-LiL/copy-to-branches-sjm@v1 env: key: main diff --git a/.vscode/settings.json b/.vscode/settings.json index 2369810..b13ceb9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,5 +20,6 @@ "workbench.activityBar.visible": true, "workbench.colorTheme": "Visual Studio Dark", "workbench.fontAliasing": "antialiased", - "workbench.statusBar.visible": true + "workbench.statusBar.visible": true, + "java.server.launchMode": "Standard" } From e3c790b353895861b1b8b67fa87faccaad62c9b2 Mon Sep 17 00:00:00 2001 From: vaskoka <74137550+vaskoka@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:57:01 +0000 Subject: [PATCH 4/6] secondSmolestItem --- src/App.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/App.java b/src/App.java index 6aeeb19..be22f2f 100644 --- a/src/App.java +++ b/src/App.java @@ -1,7 +1,15 @@ +import java.util.Arrays; + public class App { public static Integer findSecondSmallestItem(Integer[] arr) { - return 0; + + if (arr.length <= 1) { + return null; + }else { + Arrays.sort(arr); + return arr[1]; + } } public static void main(String args[]) { From 10dc5ebfed5a655d50f37819a23dc0f79579869c Mon Sep 17 00:00:00 2001 From: vaskoka <74137550+vaskoka@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:10:13 +0000 Subject: [PATCH 5/6] Find second smollest item improved --- src/App.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/App.java b/src/App.java index be22f2f..d433531 100644 --- a/src/App.java +++ b/src/App.java @@ -8,7 +8,13 @@ public static Integer findSecondSmallestItem(Integer[] arr) { return null; }else { Arrays.sort(arr); - return arr[1]; + for(int i=0; i< arr.length-1; i++){ + if (arr[i] != arr[i+1]){ + return arr[i+1]; + } + + } + return null; } } From 6953e14e298e82d439bf0d56450362046f50c052 Mon Sep 17 00:00:00 2001 From: vaskoka <74137550+vaskoka@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:32:38 +0000 Subject: [PATCH 6/6] findSecondSmallestItem2 --- src/App.java | 64 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/src/App.java b/src/App.java index d433531..fa44f66 100644 --- a/src/App.java +++ b/src/App.java @@ -1,46 +1,64 @@ import java.util.Arrays; public class App { - + public static Integer findSecondSmallestItem(Integer[] arr) { - + if (arr.length <= 1) { return null; - }else { + } else { Arrays.sort(arr); - for(int i=0; i< arr.length-1; i++){ - if (arr[i] != arr[i+1]){ - return arr[i+1]; - } - + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] != arr[i + 1]) { + return arr[i + 1]; + } + + } + return null; + } + } + + public static Integer findSecondSmallestItem2 (Integer[] arr) { + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + for (int i = 0; i < arr.length; i++){ + int current = arr[i]; + if (current < smallest){ + secondSmallest = smallest; + smallest = current; + }else if(current < secondSmallest && current != smallest){ + secondSmallest = current; } + } + if (secondSmallest == Integer.MAX_VALUE) { return null; } + return secondSmallest; } - + public static void main(String args[]) { - Integer[] arr = new Integer[]{ 5, 8, 3, 2, 6 }; + Integer[] arr = new Integer[] { 5, 8, 3, 2, 6 }; System.out.println(findSecondSmallestItem(arr)); - - Integer[] arr2 = new Integer[]{ 3, 8, 5, 2, 6 }; + + Integer[] arr2 = new Integer[] { 3, 8, 5, 2, 6 }; System.out.println(findSecondSmallestItem(arr2)); - - Integer[] arr3 = new Integer[]{ 6, 8, 5, 2, 3 }; + + Integer[] arr3 = new Integer[] { 6, 8, 5, 2, 3 }; System.out.println(findSecondSmallestItem(arr3)); - - Integer[] arr4 = new Integer[]{ 3, 3, 3, 3, 3 }; + + Integer[] arr4 = new Integer[] { 3, 3, 3, 3, 3 }; System.out.println(findSecondSmallestItem(arr4)); - - Integer[] arr5 = new Integer[]{ 3, 3, 3, 2, 3 }; + + Integer[] arr5 = new Integer[] { 3, 3, 3, 2, 3 }; System.out.println(findSecondSmallestItem(arr5)); - - Integer[] arr6 = new Integer[]{ 3, 4, 3, 3, 3 }; + + Integer[] arr6 = new Integer[] { 3, 4, 3, 3, 3 }; System.out.println(findSecondSmallestItem(arr6)); - + Integer[] arrEmpty = new Integer[] {}; System.out.println(findSecondSmallestItem(arrEmpty)); - + Integer[] arrOne = new Integer[] { 1 }; System.out.println(findSecondSmallestItem(arrOne)); - } + } } \ No newline at end of file