Search⌘ K

Solution Review 2: Display Output Using Placeholders

Explore how Rust's println! macro uses placeholders to display output on the console. This lesson helps you understand formatting with multiple placeholders and values, building foundational skills for Rust programming.

We'll cover the following...

Solution:

Rust 1.40.0
fn test() {
println!("{}", 1);
println!("{}{}", 2, 2);
println!("{}{}{}", 3, 3, 3);
println!("{}{}{}{}", 4, 4, 4, 4);
println!("{}{}{}{}{}", 5, 5, 5, 5, 5);
}

Explanation

  • On line 2, println! takes a placeholder {} and 1.

  • On line 3, ...