String Concatenation in Java: Explanation & Practice
Combine strings together
Problem summary
Build a greeting message from separate first name and last name strings.
Starter code
public class Main {
public static void main(String[] args) {
String firstName = "John";
String lastName = "Doe";
// Create and print greeting: Hello, John Doe!
}
}Expected output and test cases
- Create greeting from names
Hello, John Doe!
Hints
- Use + operator to concatenate strings
- Do not forget the space between first and last name
- Include the greeting text and exclamation mark
Related Core Java Basics exercises
- Practice Type Casting in Java
- Practice Arithmetic Operations in Java
- Practice Modulus Operator in Java
Practice all Core Java Basics exercises · Run this idea in the Java compiler