Q:

How to Concatenation in Java Using + Operator

0
How to Concatenation in Java Using + Operator or concatenation in java example java program for concatenating string or java program for print multiple values in one statement. String Concatenation in Java. using + operator.
 

Explanation:- 
Concatenation means adding two or more values, Java we have plus ( + ) operator for Concatenation two same and different type of values. The need of Concatenation and why we use?. The simple answer is when we need to add the values and printing the multiple the values in a single line we use Concatenation. Below is the example of Concatenation so you can understand very well.
 
Example:- Suppose you want to print the output of Factorial of number 5 or any other number if you don't use Concatenation then you need multiple print statement for printing the output of Factorial check the below two examples for printing the output of Factorial. factorial of 5 is 120.
 

Without using Concatenation

 
System.out.println("Factorial of  ");
System.out.println(number);
System.out.println(" is ");
System.out.println( fact );
 
So without using Concatenation your output will be 
 
Factorial of
5
is
120
 

Using Concatenation

 
System.out.println( "Factorial of  " + number + " is " + fact );
 
Now the output of the program will be 
 
Factorial of  5 is 120
 
Here number and fact are variable. You notice that both the output of the program.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

class Program3
{
public static void main(String[] args)
{
System.out.println(20+20);
System.out.println("java "+"developer");
System.out.println("Number is"+20);
System.out.println("Number is"+20+20);
System.out.println("Number is"+(20+20));
System.out.println("20+ is the Number");
System.out.println(20+20+"is the Number");
}
}

 

Output:

40

java developer

Number is20

Number is2020

Number is40

20+ is the Number

40is the Number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How to Print Different Type of Values in Java... >>
<< Variable Declaration and Initialization in Java...