Skip to content
Merged
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 added Module_1/out/production/Module_1/Lock.class
Binary file not shown.
Binary file added Module_1/out/production/Module_1/Main.class
Binary file not shown.
22 changes: 22 additions & 0 deletions Module_1/src/Lock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Arrays;

public class Lock {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Класс можно изменить

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));
}

}
55 changes: 55 additions & 0 deletions Module_1/src/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
Comment on lines +9 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта проверка по факту ничего не делает

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сортировка должны была быть написана самостоятельно

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот это зря, я говорил на лекции, сканер больше не будет работать в проекте

}
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];
}
}
Comment on lines +46 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кол-во шагов можно сократить

System.out.println(Arrays.toString(myArray));


}
}