0
0
Javaprogramming~15 mins

Using Scanner class in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Scanner class
📖 Scenario: You are creating a simple Java program that asks a user for their name and age, then prints a greeting message.
🎯 Goal: Build a Java program that uses the Scanner class to read user input from the keyboard and then prints a message using that input.
📋 What You'll Learn
Use the Scanner class to read input
Read a string input for the user's name
Read an integer input for the user's age
Print a greeting message including the name and age
💡 Why This Matters
🌍 Real World
Many Java programs need to get input from users, like command-line tools or simple interactive apps.
💼 Career
Knowing how to use Scanner is essential for beginner Java developers to build programs that interact with users.
Progress0 / 4 steps
1
Create a Scanner object
Write a line to create a Scanner object called scanner that reads from System.in.
Java
Need a hint?

Use new Scanner(System.in) to read from the keyboard.

2
Read user's name
Add a line to read a string input from scanner into a variable called name using scanner.nextLine().
Java
Need a hint?

Use scanner.nextLine() to read a full line of text.

3
Read user's age
Add a line to read an integer input from scanner into a variable called age using scanner.nextInt().
Java
Need a hint?

Use scanner.nextInt() to read an integer number.

4
Print greeting message
Write a line to print the message Hello, {name}! You are {age} years old. using System.out.println and the variables name and age.
Java
Need a hint?

Use System.out.println and string concatenation with name and age.