From the course: Learning Java 11
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Concatenating strings in Java - Java Tutorial
From the course: Learning Java 11
Concatenating strings in Java
- [Instructor] So far, we've printed out the string, "Hello world," individually, and a few variables individually, but now we are going to learn how to print them together in the same line. To do this, we need to combine string values with variables that hold strings in a print statement. Using the example from the last lesson, we can print out a student's full name, and say that student has a GPA of X, with X being the student's current GPA. In the code, we'll write System.out.println, and then access the value of the student's first name, with studentFirstName. To add on the last name, we'll add a plus sign for concatenation, combining the value of these two strings. Then we'll type the variable that holds the student's last name, studentLastName. If we put the student's first and last name together like this, there will be no space between the first and last name when it is printed out to the user. We can add a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.