Sunday, 3 April 2016

Write a program which accepts 2 strings from the user and performs string concatenation in JAVA



Write a program which accepts 2 strings from the user and performs the following operation on it.

Example1:

String1 = "JAVA"
String2 = "PYTHON"
String3 must be "JAVANOHTYP"

Example2:

String1 = "Vignesh"
String2 = "Sundeep"
String3 must be "VigneshpeednuS"

Both strings must be concatenated but after reversing the second string (as shown in string3 above).

Program:

import java.util.Scanner;

public class String_Program {
public static void main(String[ ] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter any two strings: ");
String s1 = s.next();
String s2 = s.next();
StringBuffer sb = new StringBuffer(s2);
sb.reverse( );
System.out.println(s1+sb);
}
}

Input/Output:

Enter any two strings:
Raju
Ramana
RajuanamaR


0 comments:

Post a Comment