package
stringmanipulation;
import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
public class
STRINGMANIPULATION {
public static void main(String[] args)
throws IOException {
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your choice");
System.out.println("1. To use
Length method of the String");
System.out.println("2. To use
indexof method the String");
System.out.println("3. To use
CharAt method of the String");
System.out.println("4. To use
CompareTO method of the String");
System.out.println("5. To use
Contain method of the String");
System.out.println("6. To use
endsWith method of the String");
System.out.println("7. To use
Repalce method of the String");
System.out.println("8. To use
tolowercase method of the String");
System.out.println("9. To use
touppercase method of the String");
System.out.println("10. To use
Concatenate method of the String");
int
choice=Integer.parseInt(br.readLine());
switch(choice){
case 1:
System.out.println("Enter any
String");
String s1=br.readLine();
System.out.println("Length of
the given "+ s1+" String is ="+s1.length());
break;
case 2:
System.out.println("Enter any
String");
String s2=br.readLine();
System.out.println("Enter the
character to find its position");
String s3=br.readLine();
System.out.println("String
index starts from 0");
System.out.println("Index of
the given "+ s3 +" String in
string "+s2+" is
="+s2.indexOf(s3));
break;
case 3:
System.out.println("3. To use
CharAt method of the String");
System.out.println("Enter any
String");
String s4=br.readLine();
System.out.println("Enter the
position to find its character");
int
p=Integer.parseInt(br.readLine());
System.out.println("Character
at the given position " +p+" from the string "+s4+" is =
"+s4.charAt(p));
break;
case 4:
System.out.println("4. To use
CompareTO method of the String");
System.out.println("Enter any
String");
String s5=br.readLine();
System.out.println("Enter any
String to compare");
String s6=br.readLine();
System.out.println("Comparision value of string "+s5+"
with string "+s6+" is = "+s6.compareTo(s5));
break;
case 5:
System.out.println("5. To use
Contain method of the String");
System.out.println("Enter any
String");
String s7=br.readLine();
System.out.println("Enter any
String to find ");
String s8=br.readLine();
System.out.println("Contains
string " + s8+" :"+s7.contains(s8));
break;
case 6:
System.out.println("6. To use
endsWith method of the String");
System.out.println("Enter any
String");
String s9=br.readLine();
System.out.println("Enter any
character to check at suffix ");
String s10=br.readLine();
System.out.println("Ends with
the char " + s10+" :"+s9.endsWith(s10));
break;
case 7:
System.out.println("7. To use
Repalce method of the String");
System.out.println("Enter any
String");
String s11=br.readLine();
System.out.println("Enter the
substring to replace ");
String s12=br.readLine();
System.out.println("Enter the
substring to replace with ");
String s13=br.readLine();
System.out.println("String
after Replacement is "+s11.replace(s12, s13));
break;
case 8:
System.out.println("8. To use
tolowercase method of the String");
System.out.println("Enter any
String");
String s14=br.readLine();
System.out.println("Lowercase
of the given string "+s14+" is
"+s14.toLowerCase());
break;
case 9:
System.out.println("9. To use
touppercase method of the String");
System.out.println("Enter any
String");
String s15=br.readLine();
System.out.println("Uppercase
of the given string "+s15+" is
"+s15.toUpperCase());
break;
case 10:
System.out.println("10. To
use Concatenate method of the String");
System.out.println("Enter the
first String");
String s16=br.readLine();
System.out.println("Enter the
second String");
String s17=br.readLine();
System.out.println("String
after concatenation is "+s16.concat(s17));
break;
default:
System.out.println("Please select your
choice between 1-10");
}
}
}
OUTPUT :