Initial commit
This commit is contained in:
9
exercises/01_variables/README.md
Normal file
9
exercises/01_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)
|
||||
6
exercises/01_variables/variables1.rs
Normal file
6
exercises/01_variables/variables1.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// TODO: Add the missing keyword.
|
||||
let x = 5;
|
||||
|
||||
println!("x has the value {x}");
|
||||
}
|
||||
10
exercises/01_variables/variables2.rs
Normal file
10
exercises/01_variables/variables2.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
let x = 0;
|
||||
|
||||
if x == 10 {
|
||||
println!("x is ten!");
|
||||
} else {
|
||||
println!("x is not ten!");
|
||||
}
|
||||
}
|
||||
6
exercises/01_variables/variables3.rs
Normal file
6
exercises/01_variables/variables3.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
let x: i32 = 0;
|
||||
|
||||
println!("Number {x}");
|
||||
}
|
||||
8
exercises/01_variables/variables4.rs
Normal file
8
exercises/01_variables/variables4.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
// TODO: Fix the compiler error.
|
||||
fn main() {
|
||||
let mut x = 3;
|
||||
println!("Number {x}");
|
||||
|
||||
x = 5; // Don't change this line
|
||||
println!("Number {x}");
|
||||
}
|
||||
8
exercises/01_variables/variables5.rs
Normal file
8
exercises/01_variables/variables5.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let number = "T-H-R-E-E"; // Don't change this line
|
||||
println!("Spell a number: {}", number);
|
||||
|
||||
// TODO: Fix the compiler error by changing the line below without renaming the variable.
|
||||
let number = 3;
|
||||
println!("Number plus two is: {}", number + 2);
|
||||
}
|
||||
6
exercises/01_variables/variables6.rs
Normal file
6
exercises/01_variables/variables6.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// TODO: Change the line below to fix the compiler error.
|
||||
const NUMBER: i32 = 3;
|
||||
|
||||
fn main() {
|
||||
println!("Number: {NUMBER}");
|
||||
}
|
||||
Reference in New Issue
Block a user