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

  1. Use + operator to concatenate strings
  2. Do not forget the space between first and last name
  3. Include the greeting text and exclamation mark

Related Core Java Basics exercises

Practice all Core Java Basics exercises · Run this idea in the Java compiler