mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-09 20:29:18 +00:00
feat: add array4.rs exercise
This commit is contained in:
parent
393816f393
commit
9805ee1768
27
exercises/array/array4.rs
Normal file
27
exercises/array/array4.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
// array4.rs
|
||||||
|
//
|
||||||
|
// Here is the code for how the array learns
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
// define arrays a
|
||||||
|
let a =[1,2,3,4,5];
|
||||||
|
println!("please enter an array index.");
|
||||||
|
let mut index = String::new();
|
||||||
|
std::io::stdin()
|
||||||
|
.read_line(&mut index)
|
||||||
|
.expect("Fail to read line");
|
||||||
|
let index :usize =index
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.expect("index entered was not a number");
|
||||||
|
|
||||||
|
let element = a[index];
|
||||||
|
println!("The value of is {} element : {}",index,element);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user