Skip to content
Open

done #70

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
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions src/Task1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package src;

import java.util.Arrays;

public class Task1 {
public static void main(String[] args) {


int[] arrayNumbers = {3, 8, 5, 2, 7};
System.out.println("Array: " + Arrays.toString((arrayNumbers)));

int bValue = arrayNumbers[0];
int sValue = arrayNumbers[0];

for (int i = 1; i < arrayNumbers.length; i++)

if (arrayNumbers[i] > bValue) {

bValue = arrayNumbers[i];
System.out.println("Difference is : " + (bValue - sValue));

} else if (arrayNumbers[i] < sValue)
sValue = arrayNumbers[i];


}
}
79 changes: 79 additions & 0 deletions src/Task2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package src;

public class Task2 {
public static void main(String[] args) {

int[] array = {3, 7, 4, 2, 6};
smallestAndSecondSmallest(array);

}

public static void smallestAndSecondSmallest(int[] arra) {

if (arra.length < 2) {
System.out.println("It should contain at least 2 elements !");

}

int smallest = arra[0];
int secondSmallest = Integer.MAX_VALUE;

for (int i = 1; i < arra.length;i++){
if (arra[i] < smallest) {
secondSmallest = smallest;
smallest = arra[i];
} else if (arra[i] < secondSmallest && arra[i] != smallest) {
secondSmallest = arra[i];

}
}

if (secondSmallest == Integer.MAX_VALUE) {
System.out.println("No second smallest element found.");
} else {
System.out.println("Smallest element: " + smallest);
System.out.println("Second smallest element: " + secondSmallest);


}
}}






// if (arr == null || arr.length < 2) {
// System.out.println("Array should have at least two elements.");
// return;
// }
//
// int smallest = Integer.MAX_VALUE;
// int secondSmallest = Integer.MAX_VALUE;
//
// for (int i = 0; i < arr.length; i++) {
// if (arr[i] < smallest) {
// secondSmallest = smallest;
// smallest = arr[i];
// } else if (arr[i] < secondSmallest && arr[i] != smallest) {
// secondSmallest = arr[i];
// }
// }
//
// if (secondSmallest == Integer.MAX_VALUE) {
// System.out.println("No second smallest element found.");
// } else {
// System.out.println("Smallest element: " + smallest);
// System.out.println("Second smallest element: " + secondSmallest);
// }
// }
//
// public static void main(String[] args) {
// int[] array = {3, 5, 1, 4, 2, 6};
// findSmallestAndSecondSmallest(array);
//





26 changes: 26 additions & 0 deletions src/Task3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package src;

public class Task3 {
public static double mathTask(double x, double y) {



double firstExp = Math.pow(x, 2);
double secondExp = Math.pow((4 * y / 5) - x, 2);
return firstExp + secondExp;

}

public static void main(String[] args) {

double x = 3.0;
double y = 7;
double result = mathTask(x, y);
System.out.println("Result is : " + result);



}

}