Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

01_03b #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 1 addition & 4 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
64 changes: 61 additions & 3 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -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));
}
}