JAVA · ОСНОВЫ · LESSON 03

Variable words

String and text connection · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

String stores text

For a word or phrase, you need the type String. Put the text in double quote marks.

String pet = "кот";

✦ pet is the name of the box with the word cat.

STEP 2

Slice the pieces.

The + sign connects words. If you need a space between words, put it inside quote marks.

String pet = "кот";
System.out.println("Мой " + pet);
Partial phrase
Myblank+connectpetкот

✦ It's my cat.

IN-CLASS PRACTICE

Type the code yourself

Reprint the program. Check the space after the word «Мой».

public class Main {
    public static void main(String[] args) {
        String pet = "пёс";
        System.out.println("Мой " + pet);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Save the name «Аня» to the name variable of String type. Connect the text «Привет, » and name via +, then output the phrase.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework