Finished lab_1 in Rust.
This commit is contained in:
parent
fe97b8dcde
commit
45ef70b268
|
@ -18,17 +18,12 @@ public class Lab_1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int n, m, a, b;
|
|
||||||
|
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
n = protectedInput("n", input);
|
final int n = protectedInput("n", input);
|
||||||
|
final int m = protectedInput("m", input);
|
||||||
m = protectedInput("m", input);
|
final int a = protectedInput("a", input);
|
||||||
|
final int b = protectedInput("b", input);
|
||||||
a = protectedInput("a", input);
|
|
||||||
|
|
||||||
b = protectedInput("b", input);
|
|
||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
|
fn protected_read(variable_name: &str) -> i32 {
|
||||||
|
use text_io::try_read;
|
||||||
|
loop {
|
||||||
|
print!("Enter {}: ", variable_name);
|
||||||
|
let read_result: Result<i32, _> = try_read!();
|
||||||
|
match read_result {
|
||||||
|
Ok(read_integer) => return read_integer,
|
||||||
|
Err(_e) => println!("{} must be an integer!", variable_name.to_uppercase()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// use text_io::scan;
|
let n: i32 = protected_read("n");
|
||||||
use text_io::read;
|
let m: i32 = protected_read("m");
|
||||||
|
let a: i32 = protected_read("a");
|
||||||
|
let b: i32 = protected_read("b");
|
||||||
|
|
||||||
print!("Enter m: ");
|
let s: f32 = ((b + m) as f32 / 2f32) * ((m - b + 1) * (n - a + 1)) as f32;
|
||||||
let m: f32 = read!();
|
|
||||||
|
|
||||||
print!("Enter n: ");
|
|
||||||
let n: f32 = read!();
|
|
||||||
|
|
||||||
print!("Enter a: ");
|
|
||||||
let a: f32 = read!();
|
|
||||||
|
|
||||||
print!("Enter b: ");
|
|
||||||
let b: f32 = read!();
|
|
||||||
|
|
||||||
let s: f32 = ((b + m) / 2.0) * (m - b + 1.0) * (n - a + 1.0);
|
|
||||||
|
|
||||||
println!("S = {}", s);
|
println!("S = {}", s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue