add flag "wasDivisionByZero" for lab1

This commit is contained in:
Oleksii Aleshchenko 2023-03-16 14:47:04 +02:00
parent 41ad598b79
commit 25173d66d1
1 changed files with 16 additions and 8 deletions

View File

@ -1,7 +1,7 @@
public class Lab1 {
public static void main(String[] args) {
System.out.println( (double) 0 / 0 );
System.out.println( Math.sqrt(-1) );
// System.out.println( (double) 0 / 0 );
// System.out.println( Math.sqrt(-1) );
double s = 0;
/*for (int i = 1; i <= 3; i++) { // 1) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> i = 1, 2) <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <= 3, 3) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䳿 <EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
System.out.println(i); // 4) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD> 1, 5) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2
@ -12,23 +12,31 @@ public class Lab1 {
for (int i = 0; i < array.length; i++) {
}*/
final int A = -1;
final int A = -3;
final int B = 1;
final int N = 2;
final int M = 2;
final int C = 1;
for (int i = A; i <= N; i++) {
boolean wasDivisionByZero = false;
// todo char
for (int i = A; i <= N && !wasDivisionByZero; i++) {
if (i + C == 0) { // todo optimize
System.out.println("Division by zero!");
wasDivisionByZero = true;
break; //todo flag vs return;
}
for (int j = B; j <= M; j++) {
s += (double) (i + j) / (i + C);
if (j == 0) {
System.out.println("Division by zero!");
wasDivisionByZero = true;
break;
}
s += (double) (i / j) / (i + C);
}
}
System.out.println("s = " + s);
if (!wasDivisionByZero) {
System.out.println("s = " + s);
}
}
}