mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Refining Ch03.
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
fn main() {
|
||||
let a: [i32; 5] = [-1, 0, 1, 2, 3];
|
||||
use std::io;
|
||||
|
||||
println! ("a[0]: {a.0}");
|
||||
fn main() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
println! ("请输入一个数组索引。");
|
||||
|
||||
let mut index = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut index)
|
||||
.expect("读取行失败,failed to read line");
|
||||
|
||||
let index: usize = index
|
||||
.trim()
|
||||
.parse()
|
||||
.expect("输入的所以并非一个数字");
|
||||
|
||||
let element = a[index];
|
||||
|
||||
println! ("位于索引 {index} 出的元素值为:{element}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user