You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercise-book/src/fizzbuzz.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ If you need it, we have provided a [complete solution](../../exercise-solutions/
41
41
The recommended way to print to the console in this exercise is `println!`. `println!`*always* needs a format string - it uses `{}` as a placeholder to mean **print the next argument**, like Python 3 or C#.
42
42
43
43
```rust
44
-
lets=String::from("Fizz");
44
+
lets="Fizz";
45
45
println!("The value is s is {}. That's nice.", s);
46
46
```
47
47
@@ -51,18 +51,20 @@ The two recommended ways to get a `String` type for this exercise are:
51
51
52
52
```rust
53
53
// 1.
54
-
letstring=String::from("Fizz");
54
+
lets="Fizz".to_string();
55
55
56
56
leti=4;
57
-
letstring=i.to_string();
57
+
lets=i.to_string();
58
58
59
59
// 2.
60
-
letstring=format!("Buzz");
60
+
lets=format!("Fizz");
61
61
62
62
leti=4;
63
-
letstring=format!("{}", i);
63
+
lets=format!("{}", i);
64
64
```
65
65
66
+
We'll cover these in more detail later, but either can be used to convert string literals (`"hello"`) and integers (`123`) into values of type `String`, which is all you'll need here. We'll use `format!` in our examples. It's flexible and equally efficient as other methods.
67
+
66
68
### Returning data
67
69
68
70
If you have issues returning data from multiple branches of your solution, liberally use `return`.
@@ -71,11 +73,10 @@ If you have issues returning data from multiple branches of your solution, liber
0 commit comments