0
0
Javaprogramming~15 mins

Reading string input in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Reading string input
📖 Scenario: You are creating a simple Java program that asks a user for their name and then greets them.
🎯 Goal: Build a Java program that reads a user's name from the keyboard and prints a greeting message.
📋 What You'll Learn
Use Scanner to read input from the user
Store the input in a variable called name
Print a greeting message using the name variable
💡 Why This Matters
🌍 Real World
Reading user input is essential for interactive programs like games, forms, and command-line tools.
💼 Career
Many programming jobs require handling user input safely and effectively, especially in Java backend or desktop applications.
Progress0 / 4 steps
1
Set up Scanner to read input
Write a line to create a Scanner object called scanner to read from System.in.
Java
Need a hint?

Use Scanner scanner = new Scanner(System.in); to read input from the keyboard.

2
Read the user's name
Write a line to read a full line of text from the user using scanner.nextLine() and store it in a variable called name.
Java
Need a hint?

Use String name = scanner.nextLine(); to read the user's full input line.

3
Create a greeting message
Write a line to create a variable called greeting that stores the text "Hello, " followed by the name variable and an exclamation mark.
Java
Need a hint?

Use string concatenation with "Hello, " + name + "!" to create the greeting.

4
Print the greeting message
Write a line to print the greeting variable using System.out.println().
Java
Need a hint?

Use System.out.println(greeting); to show the greeting on the screen.