mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
test2
This commit is contained in:
parent
e282e897d2
commit
7b2cf72743
9
exercises/variables/README.md
Normal file
9
exercises/variables/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Variables
|
||||||
|
|
||||||
|
In Rust, variables are immutable by default.
|
||||||
|
When a variable is immutable, once a value is bound to a name, you can’t change that value.
|
||||||
|
You can make them mutable by adding mut in front of the variable name.
|
||||||
|
|
||||||
|
## Further information
|
||||||
|
|
||||||
|
- [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html)
|
||||||
14
exercises/variables/variables1.rs
Normal file
14
exercises/variables/variables1.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// variables1.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables1` if you want a hint :)
|
||||||
|
|
||||||
|
// About this `I AM NOT DONE` thing:
|
||||||
|
// We sometimes encourage you to keep trying things on a given exercise,
|
||||||
|
// even after you already figured it out. If you got everything working and
|
||||||
|
// feel ready for the next exercise, remove the `I AM NOT DONE` comment below.
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = 5;
|
||||||
|
println!("x has the value {}", x);
|
||||||
|
}
|
||||||
14
exercises/variables/variables2.rs
Normal file
14
exercises/variables/variables2.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// variables2.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x;
|
||||||
|
x=9;
|
||||||
|
if x == 10 {
|
||||||
|
println!("Ten!");
|
||||||
|
} else {
|
||||||
|
println!("Not ten!");
|
||||||
|
}
|
||||||
|
}
|
||||||
11
exercises/variables/variables3.rs
Normal file
11
exercises/variables/variables3.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// variables3.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = 3;
|
||||||
|
println!("Number {}", x);
|
||||||
|
x = 5; // don't change this line
|
||||||
|
println!("Number {}", x);
|
||||||
|
}
|
||||||
9
exercises/variables/variables4.rs
Normal file
9
exercises/variables/variables4.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// variables4.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: i32;
|
||||||
|
println!("Number {}", x);
|
||||||
|
}
|
||||||
11
exercises/variables/variables5.rs
Normal file
11
exercises/variables/variables5.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// variables5.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let number = "T-H-R-E-E"; // don't change this line
|
||||||
|
println!("Spell a Number : {}", number);
|
||||||
|
number = 3;
|
||||||
|
println!("Number plus two is : {}", number + 2);
|
||||||
|
}
|
||||||
9
exercises/variables/variables6.rs
Normal file
9
exercises/variables/variables6.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// variables6.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
const NUMBER = 3;
|
||||||
|
fn main() {
|
||||||
|
println!("Number {}", NUMBER);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user