mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
26 lines
471 B
Rust
26 lines
471 B
Rust
|
use std::io;
|
||
|
|
||
|
fn main() {
|
||
|
let a = [1, 2, 3, 4, 5];
|
||
|
|
||
|
println!("Please enter an array index.");
|
||
|
|
||
|
let mut index = String::new();
|
||
|
|
||
|
io::stdin()
|
||
|
.read_line(&mut index)
|
||
|
.expect("Failed to read line");
|
||
|
|
||
|
let index: usize = index
|
||
|
.trim()
|
||
|
.parse()
|
||
|
.expect("Index entered was not a number");
|
||
|
|
||
|
let element = a[index];
|
||
|
|
||
|
println!(
|
||
|
"The value of the element at index {} is: {}",
|
||
|
index, element
|
||
|
);
|
||
|
}
|