From cb1f2883f72dfd887dd72985709995233388356c Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 1 Apr 2021 18:32:43 +0300
Subject: [PATCH 01/10] Version1
---
.idea/.gitignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.idea/.gitignore b/.idea/.gitignore
index 908ea44..9824f5d 100644
--- a/.idea/.gitignore
+++ b/.idea/.gitignore
@@ -1,5 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
-.idea
+.idea/*
HW_Java1.iml
\ No newline at end of file
From a76dbc42c3bac90ccfb3e226996b309531e6458b Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 1 Apr 2021 18:34:13 +0300
Subject: [PATCH 02/10] Version1
---
.idea/vcs.xml | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 .idea/vcs.xml
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
From 2d0063d4439f316346444f65851be3ae7b7c7e97 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 1 Apr 2021 18:58:08 +0300
Subject: [PATCH 03/10] Version1
---
src/main/java/Lesson1/HomeWorkApp.java | 44 +++++++++++---------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/src/main/java/Lesson1/HomeWorkApp.java b/src/main/java/Lesson1/HomeWorkApp.java
index c9d45b3..5351624 100644
--- a/src/main/java/Lesson1/HomeWorkApp.java
+++ b/src/main/java/Lesson1/HomeWorkApp.java
@@ -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() {
@@ -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 {
From fe1033114554b34391eb776c4d3fde882e616ff0 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 1 Apr 2021 22:12:48 +0300
Subject: [PATCH 04/10] Version2
---
src/main/java/Lesson2/HomeWorkApp2.java | 61 +++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 src/main/java/Lesson2/HomeWorkApp2.java
diff --git a/src/main/java/Lesson2/HomeWorkApp2.java b/src/main/java/Lesson2/HomeWorkApp2.java
new file mode 100644
index 0000000..1f35ded
--- /dev/null
+++ b/src/main/java/Lesson2/HomeWorkApp2.java
@@ -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 i) {
+ if (i % 4 == 0 & i % 100 != 0 || i % 400 == 0) {
+ return true;
+ }
+ return false;
+ }
+
+}
From 4f6464c9100b5d5e15d6403c4cf71317b0c84a30 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Thu, 1 Apr 2021 22:13:30 +0300
Subject: [PATCH 05/10] Version2
---
target/classes/Lesson1/HomeWorkApp.class | Bin 0 -> 1679 bytes
target/classes/Lesson2/HomeWorkApp2.class | Bin 0 -> 1952 bytes
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 target/classes/Lesson1/HomeWorkApp.class
create mode 100644 target/classes/Lesson2/HomeWorkApp2.class
diff --git a/target/classes/Lesson1/HomeWorkApp.class b/target/classes/Lesson1/HomeWorkApp.class
new file mode 100644
index 0000000000000000000000000000000000000000..d877e817664fa0a6f5e8f450f68135944cb92f38
GIT binary patch
literal 1679
zcmaJ?-*4Mg6#krFc2YNSlP2quY=n)LY;4PZF&O=^u7R;awhmH?5HGli)p||h$VrBf
zcz`1D0%&hT8rs7&Bwh;=S)i=E^W^+FNND1_wnf*jBGx_k-gD0V&UenacK&+$`woDM
zSczc*=VLg83qo8J;#DCoMe!P5S8zFoH!!VWM!~FtIR#e~%qzI6U_nMX22GsS@TP*d
z#C%PNw-sEMu_)sm36UAIWp?Kz1dAtDB!tRV-H?!|m@VUGueoa2%lc}Anq5UcL
zHpSjohPvx!M?$(%F*+Tqb*^;XY8oF}_QutAdzxTP-E2w76hE%q*6--0hTd8$RlBy?
zTAOx*>Gm3rrw%ZaLYscw<#pQ-h;{m@wRNMmQSCLW<{Dwc#l=N|BIz899IH&C(`!l?
zt#R<(L|&A4WYthHwnIwNvW
zaTr+@F9|V;DHW%1T15#{GTv2D!3|b)$!4C0jGHQ!aEposy~T%&Sr&mh={y{M<@~{C
ztKj_U>^R#TeP=M-bbfWVhu=C+oUP&AeSSN`&EXgH`I@$UesSkMO22fA_hQT8+Yjw;$3o9+)D2t3dw8EED$LCm#JZ|t86U8$g_#2TbU>F`qFt<|
z)!Rm`yGK?1tkX5vlAzV2A?@7*(<J#%Ej2LmLR)rYp~Vn;=vavqPN>d
zt1cnWratH5Cq?|z2c7>Pf2C`A*HprI@p<5ByvR3jf-fi#fh4X3WsbWNXNhz8KhAT)u!*iZK
z$6cPh@;=X5@)WOd>>?X6OvzMa?EifiI2^^(mo(^vGv(
zpUmceKwLnL5aK6{h^6YI1zofZ!t~7%Gf%`LNU?-DmQR$m;NdWxB6mc@39fjT8Sx}n
z0lY%3jKDugNunBjaeWe>(p_X}&XV7GEbwndFv@tL{;OEoubAK#LSQmaQfIji
G;M~7ZbZrv=
literal 0
HcmV?d00001
diff --git a/target/classes/Lesson2/HomeWorkApp2.class b/target/classes/Lesson2/HomeWorkApp2.class
new file mode 100644
index 0000000000000000000000000000000000000000..6e247ae77134713bcf8d680c5c085a40a344d47f
GIT binary patch
literal 1952
zcmaJ>OK%fb6#nk`F@8)E$9WhWLlXk66B3+;SJMCuNeY;nKatz34Fe>#}0ONSy
zhjTuh_u+zyq>76I-cx4IES(W>#e1d%+++D!L!c>T=8TEu?2J*I)MpmC6Hetb`r?#c
zH08Uq=`PKiO9Jhwl(Dpw&kZInBt`?~=4Mq)U2c;gVi(5NQPl
zFOAI`3&~uG0OCoRM-W6U+~%%~W(qXh{xwJwlV;YC<-~WQwZphe#%%@-?=%beZM4@6
zy(kb!=a-8aX+7I>xs3&
zrG_I&Xc$DFiVrlTa7iGtoy^f?b8*&S=3reA4HLL5#T9{$PU}~zB4b-?%yQRyYOPnl
zlL@S+8a~8FD$*Jzan*LMRPPc&x%##B_;pu-{dEcIP+A++uNd*ZKr3;}GAh<{t3tg|
z{nq-0+q+GOKxnIy%QLr(4B4&QN`JmoGT3BSewl{08trC2aYgo+Ju~zyhs>)N3Px^L
zpnsRX_3Y@C!xaz4I2`|D_LcIrxgh%ZPDci4vC+Q{NIv^p=Njgj8P{%CtB1
zQmRlO6s+koTnZmoO}nSLa8G-r2zx@_GQ7?By$p4_S$uCRcz3=;gAh3d7Cy9?HEWCd!yGJ40SBMJ
zw+{ccX9$FYYtW)=Xb3lQv4*BKgjUhDn?v)agQT+_cqajM5n4CKD7WYtN3RWBf^
Date: Thu, 1 Apr 2021 22:22:58 +0300
Subject: [PATCH 06/10] Revert "Version2"
This reverts commit 4f6464c9
---
target/classes/Lesson1/HomeWorkApp.class | Bin 1679 -> 0 bytes
target/classes/Lesson2/HomeWorkApp2.class | Bin 1952 -> 0 bytes
2 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 target/classes/Lesson1/HomeWorkApp.class
delete mode 100644 target/classes/Lesson2/HomeWorkApp2.class
diff --git a/target/classes/Lesson1/HomeWorkApp.class b/target/classes/Lesson1/HomeWorkApp.class
deleted file mode 100644
index d877e817664fa0a6f5e8f450f68135944cb92f38..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 1679
zcmaJ?-*4Mg6#krFc2YNSlP2quY=n)LY;4PZF&O=^u7R;awhmH?5HGli)p||h$VrBf
zcz`1D0%&hT8rs7&Bwh;=S)i=E^W^+FNND1_wnf*jBGx_k-gD0V&UenacK&+$`woDM
zSczc*=VLg83qo8J;#DCoMe!P5S8zFoH!!VWM!~FtIR#e~%qzI6U_nMX22GsS@TP*d
z#C%PNw-sEMu_)sm36UAIWp?Kz1dAtDB!tRV-H?!|m@VUGueoa2%lc}Anq5UcL
zHpSjohPvx!M?$(%F*+Tqb*^;XY8oF}_QutAdzxTP-E2w76hE%q*6--0hTd8$RlBy?
zTAOx*>Gm3rrw%ZaLYscw<#pQ-h;{m@wRNMmQSCLW<{Dwc#l=N|BIz899IH&C(`!l?
zt#R<(L|&A4WYthHwnIwNvW
zaTr+@F9|V;DHW%1T15#{GTv2D!3|b)$!4C0jGHQ!aEposy~T%&Sr&mh={y{M<@~{C
ztKj_U>^R#TeP=M-bbfWVhu=C+oUP&AeSSN`&EXgH`I@$UesSkMO22fA_hQT8+Yjw;$3o9+)D2t3dw8EED$LCm#JZ|t86U8$g_#2TbU>F`qFt<|
z)!Rm`yGK?1tkX5vlAzV2A?@7*(<J#%Ej2LmLR)rYp~Vn;=vavqPN>d
zt1cnWratH5Cq?|z2c7>Pf2C`A*HprI@p<5ByvR3jf-fi#fh4X3WsbWNXNhz8KhAT)u!*iZK
z$6cPh@;=X5@)WOd>>?X6OvzMa?EifiI2^^(mo(^vGv(
zpUmceKwLnL5aK6{h^6YI1zofZ!t~7%Gf%`LNU?-DmQR$m;NdWxB6mc@39fjT8Sx}n
z0lY%3jKDugNunBjaeWe>(p_X}&XV7GEbwndFv@tL{;OEoubAK#LSQmaQfIji
G;M~7ZbZrv=
diff --git a/target/classes/Lesson2/HomeWorkApp2.class b/target/classes/Lesson2/HomeWorkApp2.class
deleted file mode 100644
index 6e247ae77134713bcf8d680c5c085a40a344d47f..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 1952
zcmaJ>OK%fb6#nk`F@8)E$9WhWLlXk66B3+;SJMCuNeY;nKatz34Fe>#}0ONSy
zhjTuh_u+zyq>76I-cx4IES(W>#e1d%+++D!L!c>T=8TEu?2J*I)MpmC6Hetb`r?#c
zH08Uq=`PKiO9Jhwl(Dpw&kZInBt`?~=4Mq)U2c;gVi(5NQPl
zFOAI`3&~uG0OCoRM-W6U+~%%~W(qXh{xwJwlV;YC<-~WQwZphe#%%@-?=%beZM4@6
zy(kb!=a-8aX+7I>xs3&
zrG_I&Xc$DFiVrlTa7iGtoy^f?b8*&S=3reA4HLL5#T9{$PU}~zB4b-?%yQRyYOPnl
zlL@S+8a~8FD$*Jzan*LMRPPc&x%##B_;pu-{dEcIP+A++uNd*ZKr3;}GAh<{t3tg|
z{nq-0+q+GOKxnIy%QLr(4B4&QN`JmoGT3BSewl{08trC2aYgo+Ju~zyhs>)N3Px^L
zpnsRX_3Y@C!xaz4I2`|D_LcIrxgh%ZPDci4vC+Q{NIv^p=Njgj8P{%CtB1
zQmRlO6s+koTnZmoO}nSLa8G-r2zx@_GQ7?By$p4_S$uCRcz3=;gAh3d7Cy9?HEWCd!yGJ40SBMJ
zw+{ccX9$FYYtW)=Xb3lQv4*BKgjUhDn?v)agQT+_cqajM5n4CKD7WYtN3RWBf^
Date: Thu, 1 Apr 2021 22:30:59 +0300
Subject: [PATCH 07/10] Version2
---
src/main/java/Lesson2/HomeWorkApp2.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/Lesson2/HomeWorkApp2.java b/src/main/java/Lesson2/HomeWorkApp2.java
index 1f35ded..1ddf5d2 100644
--- a/src/main/java/Lesson2/HomeWorkApp2.java
+++ b/src/main/java/Lesson2/HomeWorkApp2.java
@@ -51,8 +51,8 @@ public static void printStringNTimes(String text, int n) {
}
}
- public static boolean checkYear(int i) {
- if (i % 4 == 0 & i % 100 != 0 || i % 400 == 0) {
+ public static boolean checkYear(int year) {
+ if (year % 4 == 0 & year % 100 != 0 || year % 400 == 0) {
return true;
}
return false;
From 067613c1b7fe66e33dc7a2aee4238822213b9ae9 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Sun, 4 Apr 2021 20:09:33 +0300
Subject: [PATCH 08/10] Version3
---
src/main/java/lesson3/HomeWorkApp3.java | 126 ++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 src/main/java/lesson3/HomeWorkApp3.java
diff --git a/src/main/java/lesson3/HomeWorkApp3.java b/src/main/java/lesson3/HomeWorkApp3.java
new file mode 100644
index 0000000..df566c8
--- /dev/null
+++ b/src/main/java/lesson3/HomeWorkApp3.java
@@ -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));
+ }
+}
From b9e4bd6875bdb831283fe3328a2aad5f182499a6 Mon Sep 17 00:00:00 2001
From: Ekarry <81385639+Ekarry@users.noreply.github.com>
Date: Sun, 4 Apr 2021 20:13:43 +0300
Subject: [PATCH 09/10] Version3
---
target/classes/Lesson1/HomeWorkApp.class | Bin 0 -> 1679 bytes
target/classes/Lesson2/HomeWorkApp2.class | Bin 0 -> 1927 bytes
target/classes/lesson3/HomeWorkApp3.class | Bin 0 -> 4107 bytes
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 target/classes/Lesson1/HomeWorkApp.class
create mode 100644 target/classes/Lesson2/HomeWorkApp2.class
create mode 100644 target/classes/lesson3/HomeWorkApp3.class
diff --git a/target/classes/Lesson1/HomeWorkApp.class b/target/classes/Lesson1/HomeWorkApp.class
new file mode 100644
index 0000000000000000000000000000000000000000..d877e817664fa0a6f5e8f450f68135944cb92f38
GIT binary patch
literal 1679
zcmaJ?-*4Mg6#krFc2YNSlP2quY=n)LY;4PZF&O=^u7R;awhmH?5HGli)p||h$VrBf
zcz`1D0%&hT8rs7&Bwh;=S)i=E^W^+FNND1_wnf*jBGx_k-gD0V&UenacK&+$`woDM
zSczc*=VLg83qo8J;#DCoMe!P5S8zFoH!!VWM!~FtIR#e~%qzI6U_nMX22GsS@TP*d
z#C%PNw-sEMu_)sm36UAIWp?Kz1dAtDB!tRV-H?!|m@VUGueoa2%lc}Anq5UcL
zHpSjohPvx!M?$(%F*+Tqb*^;XY8oF}_QutAdzxTP-E2w76hE%q*6--0hTd8$RlBy?
zTAOx*>Gm3rrw%ZaLYscw<#pQ-h;{m@wRNMmQSCLW<{Dwc#l=N|BIz899IH&C(`!l?
zt#R<(L|&A4WYthHwnIwNvW
zaTr+@F9|V;DHW%1T15#{GTv2D!3|b)$!4C0jGHQ!aEposy~T%&Sr&mh={y{M<@~{C
ztKj_U>^R#TeP=M-bbfWVhu=C+oUP&AeSSN`&EXgH`I@$UesSkMO| 22fA_hQT8+Yjw;$3o9+)D2t3dw8EED$LCm#JZ|t86U8$g_#2TbU>F`qFt<|
z)!Rm`yGK?1tkX5vlAzV2A?@7*(<J#%Ej2LmLR)rYp~Vn;=vavqPN>d
zt1cnWratH5Cq?|z2c7>Pf2C`A*HprI@p<5ByvR3jf-fi#fh4X3WsbWNXNhz8KhAT)u!*iZK
z$6cPh@;=X5@)WOd>>?X6OvzMa?EifiI2^^(mo(^vGv(
zpUmceKwLnL5aK6{h^6YI1zofZ!t~7%Gf%`LNU?-DmQR$m;NdWxB6mc@39fjT8Sx}n
z0lY%3jKDugNunBjaeWe>(p_X}&XV7GEbwndFv@tL{;OEoubAK#LSQmaQfIji
G;M~7ZbZrv=
literal 0
HcmV?d00001
diff --git a/target/classes/Lesson2/HomeWorkApp2.class b/target/classes/Lesson2/HomeWorkApp2.class
new file mode 100644
index 0000000000000000000000000000000000000000..afb777beadcb717039d99a94c762649bf7df4048
GIT binary patch
literal 1927
zcmaJ>OK%fb6#nk`F@8)O+j)UwXcC}tk_IW`=p^tEXECDUTmXKY@ZmkFN2NIL!nvZsxe3xS6`6f2Jpw_1r=-T`HQn
zg<(6JUR>b$rhT>re3?Zfvy@)V3V0HelRcjZ2%Qf>i#g(5kvk3PlAc+*q8A)QT7kh!
z~~tP7&y3Z|sED$w3x{c3H>*jAZY?px2S
zjq0~Df%QzoHGHVzBMoUx+pe3{`$SNwer-M3=_+uzEqYe|M*L2odB2Ge2ya8a
zI(Ns&u$pyC>ANc>gH3hiSGmzrE3=tTUXwj#j|@G_q4Mg5f{~jS=-;PLJ$riN6om)l
z9EShd_LcIrIUxGPUPlIKveEAZB%sbRI(a#pd4~ZNbV4g-8{d-Dg4)yj
z9O7ph3Jy?u?L`+3($;DYh@qWte#CKzEAsGf^p=Njg;ie#%B(m1N~&-m9IWXITnZmo
zO}l4lxMw|5L_J||1>OjLuRxuRi0^Hsd~7TAubTQ>s%=nX2s4?N3{-^RBL_br1@H!f
zI6{~SG;l&g7(^pZ({~gRTtpO8!II-PHets%sO
z(Wsr)_=?!pJ21#&$|bKn%6PISlA!kRM?vG9E1;eXSyhG2}-%*~xs60%vGWc*XieWs3oH}S~{k%ex8
VH!vzL+oMn$grK~h?{G`O(7(Y>lXd_A
literal 0
HcmV?d00001
diff --git a/target/classes/lesson3/HomeWorkApp3.class b/target/classes/lesson3/HomeWorkApp3.class
new file mode 100644
index 0000000000000000000000000000000000000000..72c4483f1de813473c8b141101cfdd24964a8463
GIT binary patch
literal 4107
zcmbVPZA@F&8Gf#>?R$MO$pu0_ut}Ydt>A!Z^VKy0TAqz1Zh0Rtw+CdTAr
znzS~JmQBsNPW#f*ty|Hg{He5rHH0RF?nkCc`?Kq5zxHdtnrTw^p-ozwL9^$aYp_XD
zsa+J`bIyCtdC&7c?{nUJ`Q0Zs<^k-)X#+v*HxNL(4+n5iLx%x3_Uq^r?I8nE92ULj
z3_Oo69Y=J$pyQ~9UBY@y$BSYjCLY}edeE!mB^_VUaa>2A4ogSBjsXpW8sZAPjfqqu
z+pIvXsXeN|-IgAtb#+G~6+bjN)*sItvHFv=ly{^DtmIKElMv&)(VZPhOek2}k&I7F
zq*FT@_NT|<$I_V-E#u=m_R`y!l}K^Erl(`nI%PE^t<-QsS2mMK4eynwS(#z(uXxC`
z0>72XSZBNAnRGNo07`t-#w8#PbqY!bGI1*#ZxNdntdgtS
zMtE@i$muk_7ENy_!kTsgL>VO$$#`lwJ3=OUgzJi;g&pzKQ7bt~6rP%Pxk2S(IuqO_
z1TAvX97?1HJ8A2*&g9Sca=o)*OfaF2S!V=>k@&!gR*Q5DNS{6JwcQG|WPB*wH94k0
z&m@LNoUSo3k{HS^d+W)2%Z`l`H9Z<#>B-DMd|yH&sjQg)h@jk$YHakQ6>S=Z{1^t~
zTX%mhS|=09!FWc&Ci|!MmD~mUihVP8(Y}>?&3-Rr&(ZWs?iG91p57DkBY{y3C;Uia
zOgvH=(teENq=HB7pA?pc?Dy???z(AT3)$D{an8ObJnjjF6l^i<@6!3r5EsmI_Fc~3
zy6+?fn~l!|hqx8un!rhcW21(wACowxpwS?pS^E}$jKK+s$4NZ5WSm6ANgAeC9ByCR
zLy*m4`xX0!4E_Ic&}6^O$fkM1uR=VC$IS8g8T(r9T*$tfdo6b^cQKTEnP*H3Zn!4*
zDp9^3s!4^K1b|w@{uxR9cJ3Va&E;NQ0W$CMD)+qWxSS=El4apdM9@$SplIQ={eJ$~
z`MOZ4c
zjP{Sl2eKecFP*$Sj4IdX+lf1T-4@1X76l6Vm
z;FtnPk95GYR$!{r5;e=4u~LI+!A?!>GuXtpN04t5zj__na+Mty
zLVS9q(aUXs-&ugo*us$yTk!>2#O55|E@JbWrf<%OsqSdZ?TN-b-e}CLMPr&Cjp-%_
zrq|@q)Jz&o-SkDx#aXyM=N|R*Z_&7=5K=k80%d%kmb2(p;1Vi}!g~{6#G^92nq_W2
z;WqAB)?CWezFFU3fnR4h;qX(y<-h?}L9iDRU47BhpbT%{a&A?C_
z1L658RD}bPOEAI#cl0t>1k~txMY(+MgQBe^_iq)!s4_pBp|igpk7ENmQH2+n-hL){
zi2Wo3_$Kosa<`TNM49edgqf+w@glaNj`n)~R>8f9sD_AAuHJ=*nQd4O{f&I+yUoEl
zqc|M@{h0FMtPTeP?mj1me-?07QAwb3Jk-u6DyNp(X<)mHWG~^{!h|^ZJVaQ)=Z9+%
zTLiwlOq&mnEu;H)9^DU2|59QoEvY-|PcuuH8KF3@5S&JnDTh8OK!XB|nI-NOSt|XM
zur@GDrgsV@;Q)J{5huVqpDjrnp)vR{ni*6#Y40cP8MbFg!S@-?5&^wToI^k}jujD5
z3Uv{^f`CeqAD!%M&)>W|WI)Kdx2ozlSmo+an}StSIIK2TvuO%e_j$%I!M`oIy;{i2
zCpv1hfLe?rGgw`2F3Ga&yh`=m=8_qdpLel;wUEUKN_f@|hO?8Z*~N>qo0@upSLR8E
zvj^?8MbStV?&Q~HvkWXud?udat}r$0g-Yv+FI^!PN0BXb
z)XK`%MvSezCC`%CeapDLv
zM;?0k5#b(Ece^Xy^#r`GzS14IFpG-dg%bm>N6))S^M6ZcG7gv5y
zQm9G_H$Y#6=1^F*fXzyIo8oWdt@o0_W@^ZJ+bl32g3kj?eR$s8H-(mEZmOqX2Et^b
zuTjSTk7~iUsIz8JnjKpH9ti#%9``#^Ft^lq=*_98+o=U0#+PF^dp)F~7wZ`CMz&jV
z91-+UsmGbye$o-cehe;$U&fb-P`R5mZB4%CXUI>>pjS~5Eiz~q6}F_R14Y+-E3{9<
z#Zd0?SdXBA|A4zFUx14&RCqsfNT_AOM9R{p1v8oqb=-rvG%byOCPKU`kn
zv+4n#hVbbcnZjdXHPS4#E&NU``|J}wc`yDdPtCjiJ#jiOQllWp7A-;{Xu<=#=iS3`c@(%4E;_LVi
zUY7ZNo(eq8+T`T-B;TsfFqbOgti?_}`z_zV&g^Zz
Date: Tue, 13 Apr 2021 17:45:05 +0300
Subject: [PATCH 10/10] Version3
---
src/main/java/lesson4/HomeworkLesson4.java | 312 +++++++++++++++++++++
1 file changed, 312 insertions(+)
create mode 100644 src/main/java/lesson4/HomeworkLesson4.java
diff --git a/src/main/java/lesson4/HomeworkLesson4.java b/src/main/java/lesson4/HomeworkLesson4.java
new file mode 100644
index 0000000..c845372
--- /dev/null
+++ b/src/main/java/lesson4/HomeworkLesson4.java
@@ -0,0 +1,312 @@
+package lesson4;
+
+import java.util.Random;
+import java.util.Scanner;
+
+public class HomeworkLesson4 {
+ private static final char DEFAULT = '_';
+ private static final char X = 'X';
+ private static final char O = 'O';
+ private static final char cpu2 = 'W', cpu3 = 'Z';
+ private static final int SIZE = 3;
+ private static final char[][] MAP = new char[SIZE][SIZE];
+ Scanner sc = new Scanner(System.in);
+ Random r = new Random();
+
+ public static void main(String[] args) {
+ HomeworkLesson4 g = new HomeworkLesson4();
+ g.initMap();
+ g.printMap();
+
+ while (true) {
+ //player turn
+ g.playerTurn();
+ g.printMap();
+ if (g.checkWin(g.X)) {
+ System.out.println("Поздравляем! Вы победитель");
+ break;
+ }
+ if (g.isMapFull()) {
+ System.out.println("Игра окончена. НИЧЬЯ");
+ break;
+ }
+
+ //AI-1 turn
+ g.aiTurn(g.O);
+ g.printMap();
+ if (g.checkWin(g.O)) {
+ System.out.println("Игра окончена. Выйграл компьютер");
+ break;
+ }
+ if (g.isMapFull()) {
+ System.out.println("Игра окончена. НИЧЬЯ");
+ break;
+ }
+
+//Too much players
+// //AI-2 turn
+// g.aiTurn(g.cpu2);
+// g.printMap();
+// if (g.checkWin(g.cpu2)) { System.out.println("Игра окончена. Выйграл компьютер_1"); break; }
+// if (g.isMapFull()) { System.out.println("Игра окончена. НИЧЬЯ"); break; }
+//
+//
+// //AI-3 turn
+// g.aiTurn(g.cpu3);
+// g.printMap();
+// if (g.checkWin(g.cpu3)) { System.out.println("Игра окончена. Выйграл компьютер_2"); break; }
+// if (g.isMapFull()) { System.out.println("Игра окончена. НИЧЬЯ"); break; }
+ }
+ }
+
+ static void initMap() {
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ MAP[i][j] = DEFAULT;
+ }
+ }
+ }
+
+ static void printMap() {
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ System.out.print(MAP[i][j] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+ void playerTurn() {
+ int x, y;
+ do {
+ System.out.println("Ваш ход. Введите координаты ячейки");
+ x = sc.nextInt() - 1;
+ y = sc.nextInt() - 1;
+ //System.out.println("Your enter coordinates: x = " + (x + 1) + ", y = " + (y + 1));
+ } while (!isCellValid(x, y));
+ MAP[y][x] = X;
+ }
+
+ boolean isCellValid(int x, int y) {
+ if (x < 0 || y < 0 || x >= 3 || y >= 3) return false;
+ if (MAP[y][x] == DEFAULT) return true;
+ return false;
+ }
+
+ boolean checkWin(char c) {
+ int countV;
+ int countH;
+ int countDiagonalA = 0;
+ int countDiagonalB = 0;
+ for (int i = 0; i <= SIZE - 1; i++) {
+ countH = 0;
+ countV = 0;
+ for (int j = 0; j <= SIZE - 1; j++) {
+ //tested horizontal check
+ if (MAP[i][j] == c) {
+ countH++;
+ if (countH == SIZE) return true;
+ }
+
+ //tested vertical check
+ if (MAP[j][i] == c) {
+ countV++;
+ if (countV == SIZE) return true;
+ }
+ }
+ // tested diagonal A "\" check
+ if (MAP[i][i] == c) {
+ countDiagonalA++;
+ if (countDiagonalA == SIZE) return true;
+ } else countDiagonalA = 0;
+ // tested diagonalB "/" check
+ if (MAP[i][SIZE - 1 - i] == c) {
+ countDiagonalB++;
+ if (countDiagonalB == SIZE) return true;
+ } else countDiagonalB = 0;
+ }
+ return false;
+ }
+
+ boolean isMapFull() {
+ for (int i = 0; i < SIZE; i++) {
+ for (int j = 0; j < SIZE; j++) {
+ if (MAP[i][j] == DEFAULT) return false;
+ }
+ }
+ return true;
+ }
+
+ void aiTurn(char c) {
+ int x = 0, y = 0, countH = 0, countHNull = 0, countV = 0, countVNull = 0, countDiagonalA = 0, countDiagonalB = 0, countDANull = 0, countDBNull = 0;
+
+ System.out.println("Компьютер сделал ход [" + c + "]:");
+
+ // 1. Atack player
+ for (int i = 0; i < SIZE; i++) {
+ countH = 0;
+ countHNull = 0;
+ countV = 0;
+ countVNull = 0;
+ for (int j = 0; j < SIZE; j++) {
+ //good vertical move
+ if (MAP[j][i] == c) countV++;
+ else if (MAP[j][i] == DEFAULT) countVNull++;
+ if ((countV == SIZE - 1) && (countVNull == 1)) {
+ //System.out.println("Компьютер всегда побеждает! vert line = " + (i + 1)); // i - horiz line
+ for (int k = 0; k < SIZE; k++) {
+ if (MAP[k][i] == DEFAULT) {
+ MAP[k][i] = c;
+ return;
+ }
+ }
+ }
+ //good Horizontal move
+ if (MAP[i][j] == c) countH++;
+ else if (MAP[i][j] == DEFAULT) countHNull++;
+ if ((countH == SIZE - 1) && (countHNull == 1)) {
+ //System.out.println("Компьютер всегда побеждает! horiz line = " + (i + 1)); // i - horiz line
+ for (int k = 0; k < SIZE; k++) {
+ if (MAP[i][k] == DEFAULT) {
+ MAP[i][k] = c;
+ return;
+ }
+ }
+ }
+
+ }
+
+ // good diagonal A "\" move
+ if (MAP[i][i] == c) countDiagonalA++;
+ else if (MAP[i][i] == DEFAULT) countDANull++;
+ if ((countDiagonalA == SIZE - 1) && (countDANull == 1)) {
+ //System.out.println("Компьютер всегда побеждает! diagA line \\");
+ for (int j = 0; j < SIZE; j++) {
+ if (MAP[j][j] == DEFAULT) {
+ MAP[j][j] = c;
+ return;
+ }
+ }
+ }
+
+ // good diagonal B "/" move
+ if (MAP[i][SIZE - 1 - i] == c) countDiagonalB++;
+ else if (MAP[i][SIZE - 1 - i] == DEFAULT) countDBNull++;
+ if ((countDiagonalB == SIZE - 1) && (countDBNull == 1)) {
+ //System.out.println("Компьютер всегда побеждает! diagB line /");
+ for (int j = 0; j < SIZE; j++) {
+ if (MAP[j][SIZE - 1 - j] == DEFAULT) {
+ MAP[j][SIZE - 1 - j] = c;
+ return;
+ }
+ }
+ }
+ }
+
+ countH = 0;
+ countHNull = 0;
+ countV = 0;
+ countVNull = 0;
+ countDiagonalA = 0;
+ countDiagonalB = 0;
+ countDANull = 0;
+ countDBNull = 0;
+
+ // 2. Blocking player
+ for (int i = 0; i < SIZE; i++) {
+ countH = 0;
+ countHNull = 0;
+ countV = 0;
+ countVNull = 0;
+ for (int j = 0; j < SIZE; j++) {
+ //good vertical move
+ if (MAP[j][i] == x) countV++;
+ else if (MAP[j][i] == DEFAULT) countVNull++;
+ if ((countV == SIZE - 1) && (countVNull == 1)) {
+ //System.out.println("Предупреждение для компьютера! vert line = " + (i + 1)); // i - horiz line
+ for (int k = 0; k < SIZE; k++) {
+ if (MAP[k][i] == DEFAULT) {
+ MAP[k][i] = c;
+ return;
+ }
+ }
+ }
+ //good Horizontal move
+ if (MAP[i][j] == x) countH++;
+ else if (MAP[i][j] == DEFAULT) countHNull++;
+ if ((countH == SIZE - 1) && (countHNull == 1)) {
+ //System.out.println("Предупреждение для компьютера! horiz line = " + (i + 1)); // i - horiz line
+ for (int k = 0; k < SIZE; k++) {
+ if (MAP[i][k] == DEFAULT) {
+ MAP[i][k] = c;
+ return;
+ }
+ }
+ }
+
+ }
+
+ // good diagonal A "\" move
+ if (MAP[i][i] == x) countDiagonalA++;
+ else if (MAP[i][i] == DEFAULT) countDANull++;
+ if ((countDiagonalA == SIZE - 1) && (countDANull == 1)) {
+ //System.out.println("Предупреждение для компьютера! diagA line \\");
+ for (int j = 0; j < SIZE; j++) {
+ if (MAP[j][j] == DEFAULT) {
+ MAP[j][j] = c;
+ return;
+ }
+ }
+ }
+
+ // good diagonal B "/" move
+ if (MAP[i][SIZE - 1 - i] == x) countDiagonalB++;
+ else if (MAP[i][SIZE - 1 - i] == DEFAULT) countDBNull++;
+ if ((countDiagonalB == SIZE - 1) && (countDBNull == 1)) {
+ //System.out.println("Предупреждение для компьютера! diagB line /");
+ for (int j = 0; j < SIZE; j++) {
+ if (MAP[j][SIZE - 1 - j] == DEFAULT) {
+ MAP[j][SIZE - 1 - j] = c;
+ return;
+ }
+ }
+ }
+ }
+
+ // 3. Taking center of map
+ if (!(SIZE % 2 == 0)) {
+ int center = (((SIZE + 1) / 2) - 1);
+ if (MAP[center][center] == DEFAULT) {
+ MAP[center][center] = c;
+ return;
+ }
+ }
+
+ // 4. Taking diagonal points of map
+ if (MAP[0][0] == DEFAULT) {
+ MAP[0][0] = c;
+ return;
+ }
+ if (MAP[0][MAP.length - 1] == DEFAULT) {
+ MAP[0][MAP.length - 1] = c;
+ return;
+ }
+ if (MAP[MAP.length - 1][0] == DEFAULT) {
+ MAP[MAP.length - 1][0] = c;
+ return;
+ }
+ if (MAP[MAP.length - 1][MAP.length - 1] == DEFAULT) {
+ MAP[MAP.length - 1][MAP.length - 1] = c;
+ return;
+ }
+
+ // 5. random move
+ //System.out.println("AI random");
+ do {
+ x = r.nextInt(SIZE);
+ y = r.nextInt(SIZE);
+ } while (!isCellValid(x, y));
+ MAP[y][x] = c;
+ System.out.println("AI X: " + (x + 1) + " Y: " + (y + 1));
+ }
+}
\ No newline at end of file
| | |