-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patharrow.rs
52 lines (42 loc) · 1.1 KB
/
arrow.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::env;
fn print_arrow(size: usize) {
let mut line = 0;
let mut text: String;
while line < size {
text = " ".repeat(size-line);
text.push_str("*");
if line != 0 {
text.push_str(&" ".repeat(1+(line-1)*2));
text.push_str("*");
}
println!("{}", text);
line = line+1;
}
text = "*".repeat(size*2+1);
println!("{}", text);
line = 0;
while line < size {
text = " ".repeat(size);
text.push_str("*");
println!("{}", text);
line = line+1;
}
}
fn main() {
let args: Vec<String> = env::args().collect();
match args.len() {
1 => {
println!("[{}] Please enter one argument", args[0]);
},
2 => {
let result = args[1].parse::<usize>();
match result {
Ok(foo) => print_arrow(foo),
Err(err) => println!("[{}]First argument must be an integer !", args[0]),
}
},
x => {
println!("[{}] Please enter ONLY one argument", args[0]);
},
}
}