0
0
Javaprogramming~15 mins

Output formatting basics in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Output formatting basics
📖 Scenario: You are creating a simple Java program to display a person's name and age in a clear and friendly way. This is like writing a small introduction card.
🎯 Goal: Build a Java program that stores a person's name and age, then prints a formatted sentence introducing the person.
📋 What You'll Learn
Create a variable for the person's name
Create a variable for the person's age
Use System.out.printf to print the formatted output
💡 Why This Matters
🌍 Real World
Output formatting is used in many programs to show information clearly, like printing reports, messages, or user data.
💼 Career
Knowing how to format output is a basic skill for software developers, especially when creating user interfaces or logs.
Progress0 / 4 steps
1
Create variables for name and age
Create a String variable called name and set it to "Alice". Create an int variable called age and set it to 30.
Java
Need a hint?

Use String name = "Alice"; and int age = 30; inside the main method.

2
Add a format string
Create a String variable called format and set it to "My name is %s and I am %d years old.".
Java
Need a hint?

Use String format = "My name is %s and I am %d years old."; to prepare the format.

3
Print formatted output using printf
Use System.out.printf with the format string, passing name and age as arguments.
Java
Need a hint?

Use System.out.printf(format, name, age); to print the formatted sentence.

4
Print a newline after the formatted output
Add System.out.println() after the printf line to move to the next line.
Java
Need a hint?

Use System.out.println(); to print a newline after the formatted text.