add break with label (commented in line 34) and return for lab1

This commit is contained in:
Oleksii Aleshchenko 2023-03-16 15:00:12 +02:00
parent 25173d66d1
commit 6ab6cc17db
1 changed files with 5 additions and 4 deletions

View File

@ -13,14 +13,14 @@ public class Lab1 {
}*/ }*/
final int A = -3; final int A = -3;
final int B = 1; final int B = 0;
final int N = 2; final int N = 2;
final int M = 2; final int M = 2;
final int C = 1; final int C = 1;
boolean wasDivisionByZero = false; boolean wasDivisionByZero = false;
// todo char // todo char
for (int i = A; i <= N && !wasDivisionByZero; i++) { myLabel:for (int i = A; i <= N && !wasDivisionByZero; i++) {
if (i + C == 0) { // todo optimize if (i + C == 0) { // todo optimize
System.out.println("Division by zero!"); System.out.println("Division by zero!");
wasDivisionByZero = true; wasDivisionByZero = true;
@ -29,8 +29,9 @@ public class Lab1 {
for (int j = B; j <= M; j++) { for (int j = B; j <= M; j++) {
if (j == 0) { if (j == 0) {
System.out.println("Division by zero!"); System.out.println("Division by zero!");
wasDivisionByZero = true; return;
break; // wasDivisionByZero = true;
// break myLabel;
} }
s += (double) (i / j) / (i + C); s += (double) (i / j) / (i + C);
} }