Compare commits
No commits in common. "a8cbadbe7d0c0fef9fec7c981af1aa5e53ff9925" and "ca2b85ef9e64eb885fcfbb98b01d2ee50af2b329" have entirely different histories.
a8cbadbe7d
...
ca2b85ef9e
|
@ -2,16 +2,19 @@ import java.util.Scanner;
|
||||||
|
|
||||||
public class lab_1 {
|
public class lab_1 {
|
||||||
|
|
||||||
public static int protectedInput(String variableToRead, Scanner input) {
|
public static int protectedInput(String variable_to_read, Scanner input) {
|
||||||
|
int read_variable;
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
System.out.printf("Enter %s: ", variableToRead);
|
System.out.printf("Enter %s: ", variable_to_read);
|
||||||
return input.nextInt();
|
read_variable = input.nextInt();
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.printf("%s must be an integer.\n", variableToRead.toUpperCase());
|
System.out.printf("%s must be an integer.\n", variable_to_read.toUpperCase());
|
||||||
input.nextLine();
|
input.nextLine();
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
return read_variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -24,7 +27,7 @@ public class lab_1 {
|
||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
final float s = ((float) (b + m) / 2) * (m - b + 1) * (n - a + 1);
|
float s = ((float) (b + m) / 2) * (m - b + 1) * (n - a + 1);
|
||||||
|
|
||||||
System.out.println("S = " + s);
|
System.out.println("S = " + s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
fun protectedInput(variableName: String): Int {
|
|
||||||
do {
|
|
||||||
try {
|
|
||||||
print("Enter $variableName: ")
|
|
||||||
return readln().toInt()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
println("${variableName.uppercase()} must be an integer!")
|
|
||||||
}
|
|
||||||
} while (true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val n: Int = protectedInput("n")
|
|
||||||
val m: Int = protectedInput("m")
|
|
||||||
val a: Int = protectedInput("a")
|
|
||||||
val b: Int = protectedInput("b")
|
|
||||||
|
|
||||||
val s: Float = (b + m).toFloat() / 2 * (m - b + 1) * (n - a + 1)
|
|
||||||
|
|
||||||
println("S = $s")
|
|
||||||
}
|
|
Loading…
Reference in New Issue