String
String
Write a program in Java to accept 2 Strings from the user and perform String
manipulation operations on them such as Concatenation, Reversing, Comparing, Length
& Copy.
CODE:
import java.util.*;
public class StringMan
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 strings:");
String s=sc.nextLine();
String m=sc.nextLine();
String con=s.concat(m);
System.out.println("Concatenation of the 2 strings is:"+con);
int l=s.length();
int k=m.length();
System.out.println("Length of the string "+s+" is "+l);
System.out.println("Length of the string "+m+" is "+k);
int z=s.compareTo(m);
if(z==0)
{
System.out.println("Both strings are equal");
}
else
{
System.out.println("Both strings are unequal");
}
System.out.println("");
OUTPUT: