-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); | ||
| } | ||
|
|
||
| } | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кол-во шагов можно сократить |
||
| System.out.println(Arrays.toString(myArray)); | ||
|
|
||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Класс можно изменить