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
2 changes: 1 addition & 1 deletion .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 .idea/vcs.xml

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

44 changes: 18 additions & 26 deletions src/main/java/Lesson1/HomeWorkApp.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package Lesson1;

import java.util.Scanner;

public class HomeWorkApp {

public static void main(String[] args) {
printThreeWords();
checkSumSign();
printColor();
compareNumbers();
checkSumSign(3, 6);
checkSumSign(-1, 1);
checkSumSign(-2, 1);
printColor(-7);
printColor(0);
printColor(7);
printColor(100);
printColor(101);
compareNumbers(9, 9);
compareNumbers(9, 5);
compareNumbers(3, 9);
}

public static void printThreeWords() {
Expand All @@ -16,42 +23,27 @@ public static void printThreeWords() {
System.out.println("Apple");
}

public static void checkSumSign() {
Scanner in = new Scanner(System.in);
System.out.println("Введите первое число");
int a = in.nextInt();
System.out.println("Введите второе число");
int b = in.nextInt();
public static void checkSumSign(int a, int b) {
int sum = a + b;
if (sum >= 0) { // если сумма меньше или равна нулю
if (sum >= 0) { // если сумма больше или равна нулю
System.out.println("Сумма положительная");
} else {
System.out.println("Сумма отрицательная");
}
}

public static void printColor() {
Scanner in = new Scanner(System.in);
System.out.println("Введите число");
int value = in.nextInt();
public static void printColor(int value) {
if (value <= 0) {
System.out.println("Красный");
}
if (value <= 100){
} else if (value <= 100) {
System.out.println("Желтый");
}
if (value > 100){
} else if (value > 100) {
System.out.println("Зеленый");
}

}

public static void compareNumbers() {
Scanner in = new Scanner(System.in);
System.out.println("Введите первое число");
int a = in.nextInt();
System.out.println("Введите второе число");
int b = in.nextInt();
public static void compareNumbers(int a, int b) {
if (a >= b) {
System.out.println(a + " >= " + b);
} else {
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/Lesson2/HomeWorkApp2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package Lesson2;

public class HomeWorkApp2 {

public static void main(String[] args) {
checkSum(7, 5);
checkSum(3, -2);
checkSum(10, 11);
printChekInt(10);
printChekInt(-1);
printChekInt(0);
checkInt(-1);
checkInt(0);
checkInt(2);
printStringNTimes("Число равно ", 6);
checkYear(200);
checkYear(400);
checkYear(600);
checkYear(2020);
checkYear(2022);
}

public static boolean checkSum(int a, int b) {
int sum = a + b;
if (sum > 9 & sum < 21) {
return true;
}
return false;
}

public static void printChekInt(int n) {
if (n >= 0) {
System.out.println("Число " + n + " положительное");
} else {
System.out.println("Число " + n + " отрицательное");
}
}

public static boolean checkInt(int i) {
if (i == 0) {
System.out.println("Число равно нулю");
} else if (i < 0) {
return true;
}
return false;
}

public static void printStringNTimes(String text, int n) {
for (int i = 0; i < n; i++) {
System.out.println(text + (i + 1));
}
}

public static boolean checkYear(int year) {
if (year % 4 == 0 & year % 100 != 0 || year % 400 == 0) {
return true;
}
return false;
}

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

import java.util.Arrays;

public class HomeWorkApp3 {
public static void main(String[] args) {
arrayZeroOne();
createArray();
arrayChangeTwo();
createArray2(7);
createArrayLenValue(5, 9);
findMiniMaxArray(16, -3, 7);
System.out.println(checkBalance(new int[]{1, 2, 1, 1, 1})); // true
System.out.println(checkBalance(new int[]{2, 3, 1, 2, 11})); // false
System.out.println(checkBalance(new int[]{5, 5, 10})); //true
shiftArray(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, -3);
shiftArray(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 0);
shiftArray(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 4);

}

public static void arrayZeroOne() {
int[] array = new int[]{1, 1, 0, 0, 1, 0, 1, 1, 0, 0};
System.out.println("Начальный массив: " + (Arrays.toString(array)));
for (int i = 0; i < array.length; i++) {
if (array[i] == 0) array[i] = 1;
else array[i] = 0;
}
System.out.println("Массив после замены: " + (Arrays.toString(array)));
}

public static void createArray() {
int[] array = new int[100];
System.out.println("\nБыл создан массив: " + (Arrays.toString(array)));
for (int i = 0; i < array.length; i++) {
array[i] = i + 1;
}
}

public static void arrayChangeTwo() {
int[] array = new int[]{1, 5, 3, 2, 11, 4, 5, 2, 4, 8, 9, 1};
System.out.println("\nНачальный массив: " + (Arrays.toString(array)));
for (int i = 0; i < array.length; i++) {
if (array[i] < 6) array[i] = array[i] * 2;
}
System.out.println("Массив после замены: " + (Arrays.toString(array)));
}

static void createArray2(int length) { // length of array
int[][] array = new int[length][length];
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if ((i + j) % 2 == 0) {
array[i][j] = 1;
} else array[i][j] = 0;
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}

static void createArrayLenValue(int len, int initialValue) {
int[] array = new int[len];
for (int i = 0; i < array.length; i++) {
array[i] = initialValue;
}
System.out.println("\nБыл создан массив: " + (Arrays.toString(array)));
}

static void findMiniMaxArray(int length, int min, int max) {
int[] array = new int[length];
for (int i = 0; i < array.length; i++) {
array[i] = (int) (min + Math.random() * max);
}
System.out.println("\nБыл создан массив: " + (Arrays.toString(array)));
min = 0;
max = 0;
for (int i = 0; i < array.length; i++) {
min = (min < array[i]) ? min : array[i];
max = (max > array[i]) ? max : array[i];
}
System.out.println("\nМинимальное значение в массиве: " + min + "\nМаксимальное значение в массиве: " + max);
}

static boolean checkBalance(int[] array) {
int leftSum, rightSum;
for (int i = 0; i < array.length + 1; i++) {
leftSum = 0;
rightSum = 0;
for (int j = 0; j < i; j++) {
leftSum += array[j];
}
for (int j = i; j < array.length; j++) {
rightSum += array[j];
}
if (leftSum == rightSum) return true;
}
return false;
}

static void shiftArray(int[] array, int n) {
System.out.println("\nНачальный массив: " + (Arrays.toString(array)));
if (n == 0) {
System.out.print("Сдвиг не может быть равен нулю (n = " + n + ")" + "\nПоэтому массив не будет изменен: ");
} else if (n > 0) {
System.out.print("Сдвиг будет вправо, т.к. n = " + n + "\nМассив после изменения: ");
for (int i = 0; i < n; i++) {
int tmp = array[array.length - 1];
for (int j = array.length - 1; j > 0; j--) {
array[j] = array[j - 1];
}
array[0] = tmp;
}
} else {
System.out.println("Сдвиг будет влево, так как n = " + n + "\nМассив после изменения: ");
for (int i = 0; i < n * (-1); i++) {
int tmp = array[0];
for (int j = 0; j < array.length - 1; j++) {
array[j] = array[j + 1];
}
array[array.length - 1] = tmp;
}
}
System.out.println(Arrays.toString(array));
}
}
Loading