Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my code to concatenate strings in Java:

public class StackOverflowTest {  

    public static void main(String args[]) {

        int theNumber = 42;

        System.out.println("Your number is " . theNumber . "!");

    }

}

When I run it, it's not working. Can anyone tell me how to concatenate two strings In Java? 

1 Answer

0 votes
by (19.7k points)

Use the below code to concatenate Strings using the + operator:

System.out.println("Your number is " + theNumber + "!");

When you run this, theNumber is implicitly converted to the String "42".

Interested in Java? Check out this Java tutorial by Intellipaat.

Related questions

0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer
asked Jul 14, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Apr 28, 2020 in SQL by Sudhir_1997 (55.6k points)

Browse Categories

...