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" } 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 diff --git a/src/App.java b/src/App.java index 945d723..fa44f66 100644 --- a/src/App.java +++ b/src/App.java @@ -1,6 +1,64 @@ +import java.util.Arrays; + public class App { - - public static void main(String[] args) { - + + public static Integer findSecondSmallestItem(Integer[] arr) { + + if (arr.length <= 1) { + return null; + } else { + Arrays.sort(arr); + 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 }; + 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