0% found this document useful (0 votes)
13 views

String

Uploaded by

Mithilesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

String

Uploaded by

Mithilesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROBLEM STATEMENT:

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("");

System.out.print("Reverse of the string "+s+" is: ");


for(int i=l-1;i>=0;i--)
{
System.out.print(s.charAt(i));
}
System.out.println("");

System.out.print("Reverse of the string "+m+" is: ");


for(int i=k-1;i>=0;i--)
{
System.out.print(m.charAt(i));
}
System.out.println("");
String copy=s.substring(0);
String popy=m.substring(0);

System.out.println("Copied String are: "+copy+" and "+popy);


}
}

OUTPUT:

You might also like