Skip to content
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
38 changes: 38 additions & 0 deletions ab-java-loops-and-version-control/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions ab-java-loops-and-version-control/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ab-java-loops-and-version-control/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ab-java-loops-and-version-control/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ab-java-loops-and-version-control/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions ab-java-loops-and-version-control/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>ab-java-loops-and-version-control</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
54 changes: 54 additions & 0 deletions ab-java-loops-and-version-control/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
public class Main {

private static final int x = 2;
private static final int y = 5;

public static void main(String[] args) {

}

public static int minMaxDifference(int[] nums) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;

for (int num : nums) {
if (num < min) {
min = num;
}
if (num > max) {
max = num;
}
}

return max - min;
}

public static void printSmallestAndSecondSmallest(int[] arr) {
if (arr.length < 2) {
System.out.println("Array must contain at least two elements.");
return;
}

int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

for (int num : arr) {
if (num < smallest) {
secondSmallest = smallest;
smallest = num;
} else if (num < secondSmallest && num != smallest) {
secondSmallest = num;
}
}

if(secondSmallest == Integer.MAX_VALUE){
secondSmallest = smallest;
}
System.out.println("Smallest: " + smallest + ", Second Smallest: " + secondSmallest);

}

public static int expression(){
return x*x + (4*y/5 - x)*(4*y/5 - x);
}
}