2023-03-09 16:01:01 +02:00
|
|
|
|
public class Lab1 {
|
|
|
|
|
public static void main(String[] args) {
|
2023-03-16 14:47:04 +02:00
|
|
|
|
// System.out.println( (double) 0 / 0 );
|
|
|
|
|
// System.out.println( Math.sqrt(-1) );
|
2023-03-09 16:01:01 +02:00
|
|
|
|
double s = 0;
|
|
|
|
|
/*for (int i = 1; i <= 3; i++) { // 1) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> i = 1, 2) <20><><EFBFBD><EFBFBD> <20> <= 3, 3) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䳿 <20> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>,
|
|
|
|
|
System.out.println(i); // 4) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><> 1, 5) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> 2
|
|
|
|
|
// s = s + i;
|
|
|
|
|
s += i;
|
|
|
|
|
}*/
|
|
|
|
|
/*int[] array = new int[2];
|
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
|
|
|
|
|
|
}*/
|
2023-03-16 14:47:04 +02:00
|
|
|
|
final int A = -3;
|
2023-03-09 16:01:01 +02:00
|
|
|
|
final int B = 1;
|
|
|
|
|
final int N = 2;
|
|
|
|
|
final int M = 2;
|
|
|
|
|
|
|
|
|
|
final int C = 1;
|
2023-03-16 14:47:04 +02:00
|
|
|
|
boolean wasDivisionByZero = false;
|
|
|
|
|
// todo char
|
|
|
|
|
for (int i = A; i <= N && !wasDivisionByZero; i++) {
|
2023-03-09 16:01:01 +02:00
|
|
|
|
if (i + C == 0) { // todo optimize
|
|
|
|
|
System.out.println("Division by zero!");
|
2023-03-16 14:47:04 +02:00
|
|
|
|
wasDivisionByZero = true;
|
2023-03-09 16:01:01 +02:00
|
|
|
|
break; //todo flag vs return;
|
|
|
|
|
}
|
|
|
|
|
for (int j = B; j <= M; j++) {
|
2023-03-16 14:47:04 +02:00
|
|
|
|
if (j == 0) {
|
|
|
|
|
System.out.println("Division by zero!");
|
|
|
|
|
wasDivisionByZero = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s += (double) (i / j) / (i + C);
|
2023-03-09 16:01:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-16 14:47:04 +02:00
|
|
|
|
if (!wasDivisionByZero) {
|
|
|
|
|
System.out.println("s = " + s);
|
|
|
|
|
}
|
2023-03-09 16:01:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|