mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
445 B
23 lines
445 B
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 {index} is: {element}");
|
|
}
|