Wednesday, 30 March 2016

How to Concatenation in Java Using + Operator

Problem:- 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.

Check This:- HackerRank solution for C++ Domain.


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.

How to Concatenation in Java Using + Operator


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:-

How to Concatenation in Java Using + Operator

You May Also See


1. Java Program To Print ASCII Value Of Character

2. Java Program To Find Area Of Triangle

3. Java Program to Convert a person's name in Abbreviated

4. Java Program For Calculate A Simple Interest

5. Java Program For Find The Gross Salary Of An Employee

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Prashant Chaturvedi

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

1 comment: