2023-03-22 17:02:31 +02:00
|
|
|
import java.util.Scanner;
|
|
|
|
|
2023-05-07 15:19:06 +03:00
|
|
|
public class lab_1 {
|
|
|
|
|
2023-05-07 22:20:31 +03:00
|
|
|
public static int protectedInput(String variableToRead, Scanner input) {
|
2023-05-02 09:58:31 +03:00
|
|
|
do {
|
|
|
|
try {
|
2023-05-07 22:20:31 +03:00
|
|
|
System.out.printf("Enter %s: ", variableToRead);
|
2023-05-07 23:14:24 +03:00
|
|
|
return input.nextInt();
|
2023-05-02 09:58:31 +03:00
|
|
|
} catch (Exception e) {
|
2023-05-07 22:20:31 +03:00
|
|
|
System.out.printf("%s must be an integer.\n", variableToRead.toUpperCase());
|
2023-05-02 09:58:31 +03:00
|
|
|
input.nextLine();
|
|
|
|
}
|
|
|
|
} while (true);
|
2023-05-03 10:32:23 +03:00
|
|
|
}
|
2023-03-22 17:02:31 +02:00
|
|
|
|
2023-05-03 10:32:23 +03:00
|
|
|
public static void main(String[] args) {
|
|
|
|
Scanner input = new Scanner(System.in);
|
2023-03-22 17:02:31 +02:00
|
|
|
|
2023-05-07 09:26:25 +03:00
|
|
|
final int n = protectedInput("n", input);
|
|
|
|
final int m = protectedInput("m", input);
|
|
|
|
final int a = protectedInput("a", input);
|
|
|
|
final int b = protectedInput("b", input);
|
2023-03-22 17:02:31 +02:00
|
|
|
|
2023-04-26 14:37:46 +03:00
|
|
|
input.close();
|
|
|
|
|
2023-05-07 23:14:24 +03:00
|
|
|
final float s = ((float) (b + m) / 2) * (m - b + 1) * (n - a + 1);
|
2023-03-22 17:02:31 +02:00
|
|
|
|
|
|
|
System.out.println("S = " + s);
|
|
|
|
}
|
|
|
|
}
|