diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a0ccf77 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Environment-dependent path to Maven home directory +/mavenHomeManager.xml diff --git a/.idea/lab-java-loops-and-version-control.iml b/.idea/lab-java-loops-and-version-control.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-loops-and-version-control.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e6be3f1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dfda522 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/src/Main.java b/.idea/src/Main.java new file mode 100644 index 0000000..186da6d --- /dev/null +++ b/.idea/src/Main.java @@ -0,0 +1,71 @@ +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + int[] numbers = {10, 5, 8, 3, 12}; + + findDifference(numbers); + findSmallest(numbers); + + double x = 2; // Pre-set value for x + double y = 3; // Pre-set value for y + + double result = calculateExpression(x, y); + System.out.println("Result: " + result); + + } + + // Task 1 + + public static void findDifference(int[] arr) { + int min = arr[0]; + int max = arr[0]; + + for (int i = 1; i < arr.length; i++) { + if (arr[i] < min) { + min = arr[i]; + } + if (arr[i] > max) { + max = arr[i]; + } + } + + int difference = max - min; + System.out.println("Difference: " + difference); + } + + + // Task 2 + + public static void findSmallest(int[] arr) { + 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; + } + } + + System.out.println("Smallest element: " + smallest); + System.out.println("Second smallest element: " + secondSmallest); + } + + // Task 3 + + public static double calculateExpression(double x, double y) { + double term1 = Math.pow(x, 2); + double term2 = Math.pow((4 * y / 5 - x), 2); + + return term1 + term2; + } +} + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file