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
3 changes: 3 additions & 0 deletions lab104/src/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions lab104/src/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions lab104/src/.idea/modules.xml

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

7 changes: 7 additions & 0 deletions lab104/src/.idea/vcs.xml

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

68 changes: 68 additions & 0 deletions lab104/src/Main.java
Original file line number Diff line number Diff line change
@@ -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;

}
}
11 changes: 11 additions & 0 deletions lab104/src/lab104.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>