diff --git a/lab104/src/.idea/.gitignore b/lab104/src/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/lab104/src/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/lab104/src/.idea/misc.xml b/lab104/src/.idea/misc.xml new file mode 100644 index 0000000..e6be3f1 --- /dev/null +++ b/lab104/src/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lab104/src/.idea/modules.xml b/lab104/src/.idea/modules.xml new file mode 100644 index 0000000..add5563 --- /dev/null +++ b/lab104/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lab104/src/.idea/vcs.xml b/lab104/src/.idea/vcs.xml new file mode 100644 index 0000000..fdf1fc8 --- /dev/null +++ b/lab104/src/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/lab104/src/Main.java b/lab104/src/Main.java new file mode 100644 index 0000000..9eae2ab --- /dev/null +++ b/lab104/src/Main.java @@ -0,0 +1,68 @@ +import javax.crypto.spec.PSource; +import java.util.Arrays; + +public class Main { + public static void main(String[] args) { + + int [] arrayNumbers = {10, 63, 74, 8, 2}; + + /// TASK 1 + int result = calculateDifference(arrayNumbers); + System.out.println("The difference between the largest and smallest values is " + result); + + /// TASK 2 + findNumbers(arrayNumbers); + + /// TASK 3 + double x = 2; + double y = 4; + + double expressionResult = calculate(x, y); + System.out.println("Expression result: "+ expressionResult); + } + + public static int calculateDifference(int[] arrayNumbers){ + + int maxValue = arrayNumbers[0]; + int minValue = arrayNumbers[0]; + + for (int i = 1; i < arrayNumbers.length; i++) { + if (arrayNumbers[i] > maxValue) { + maxValue = arrayNumbers[i]; + } + else if (arrayNumbers[i] < minValue) { + minValue = arrayNumbers[i]; + } + } + + return maxValue - minValue; + + } + + public static void findNumbers(int[] arrayNumbers) { + + int smallest = arrayNumbers[0]; + int secondSmallest = arrayNumbers[0]; + + for (int j = 1; j < arrayNumbers.length; j++) { + if (arrayNumbers[j] < smallest) { + secondSmallest = smallest; + smallest = arrayNumbers[j]; + } + else if (arrayNumbers[j] < secondSmallest) { + secondSmallest = arrayNumbers[j]; + } + } + + System.out.println("The smallest and second smallest numbers of the array are: " + smallest +" y "+ secondSmallest); + + } + + public static double calculate(double x, double y) { + double outParenthesis = Math.pow(x, 2); + double inParenthesis = Math.pow((4*y/5-x), 2); + + return outParenthesis + inParenthesis; + + } +} \ No newline at end of file diff --git a/lab104/src/lab104.iml b/lab104/src/lab104.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/lab104/src/lab104.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file