在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
随机数、数字对比、控制台输入 use std::io; use std::cmp::Ordering; use rand::Rng; fn main() { println!("please input a number(1-10):"); let mut ss = String::new(); io::stdin().read_line(&mut ss).expect("please input a value"); println!("you input:{}",ss); let snum = rand::thread_rng().gen_range(1,10); println!("rand number:{}",snum); let ss: u32 = ss.trim().parse().ok().expect("please input a number"); match ss.cmp(&snum) { Ordering::Less => println!("too smalll"), Ordering::Greater => println!("too big"), Ordering::Equal => println!("you win!"), } }
Cargo.toml [package] name = "a1_guess" version = "0.1.0" authors = ["tanpengfei3 <[email protected]>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] rand = "0.7.3"
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论