diff --git a/Module_1/out/production/Module_1/Lock.class b/Module_1/out/production/Module_1/Lock.class new file mode 100644 index 0000000..8d3673d Binary files /dev/null and b/Module_1/out/production/Module_1/Lock.class differ diff --git a/Module_1/out/production/Module_1/Main.class b/Module_1/out/production/Module_1/Main.class new file mode 100644 index 0000000..6707b63 Binary files /dev/null and b/Module_1/out/production/Module_1/Main.class differ diff --git a/Module_1/src/Lock.java b/Module_1/src/Lock.java new file mode 100644 index 0000000..2cf0b08 --- /dev/null +++ b/Module_1/src/Lock.java @@ -0,0 +1,22 @@ +import java.util.Arrays; + +public class Lock { + private final int[] myArray; + + public Lock(int[] myArray) { + this.myArray = myArray; + } + + public int[] getArray() { + if (myArray == null) { + return null; + } else { + return myArray.clone(); + } + } + + public void printArray() { + System.out.println(Arrays.toString(myArray)); + } + +} diff --git a/Module_1/src/Main.java b/Module_1/src/Main.java new file mode 100644 index 0000000..7138d15 --- /dev/null +++ b/Module_1/src/Main.java @@ -0,0 +1,55 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + System.out.print("Write the length of array from 10 to 100"); + int x = in.nextInt(); + if (x < 10) { + System.out.print("The length of array must be >= 10"); + } else { + System.out.printf("The length of array is %d \n", x); + } + int[] myArray = new int[x]; + for (int i = 0; i < myArray.length; i++) { + myArray[i] = ((int) (Math.random() * 201) - 100); + } + System.out.println(Arrays.toString(myArray)); + + System.out.print("Write 1 if you want choose increase ang 2 if you want choose decrease"); + int y = in.nextInt(); + + if (y == 1) { + Arrays.sort(myArray); + System.out.println(Arrays.toString(myArray)); + } + else if (y == 2) { + for (int i = 0; i < myArray.length; i++) { + for (int j = myArray.length - 1; j > i; j--) { + if (myArray[j] > myArray[j - 1]) { + int temp = myArray[j]; + myArray[j] = myArray[j - 1]; + myArray[j - 1] = temp; + } + } + } + System.out.println(Arrays.toString(myArray)); + in.close(); + } + else { + System.out.print("Write only 1 or 2"); + } + + in.close(); + System.out.print("The array with every third element in cube: "); + for (int i = 0; i < myArray.length; i++) { + if ((i+1)%3==0) { + myArray[i] = myArray[i] * myArray[i] * myArray[i]; + } + } + System.out.println(Arrays.toString(myArray)); + + + } + } \ No newline at end of file