Professional Documents
Culture Documents
import java.io.*;
class StringTest
try
System.out.println("Enter a string");
String s1=dts.readLine();
String s2,s3;
int position,index;
char ind;
boolean eql;
int ch=Integer.parseInt(dts.readLine());
switch(ch)
case 1:
System.out.println("Lower Case");
s2=s1.toLowerCase();
break;
case 2:
System.out.println("Upper Case");
s2=s1.toUpperCase();
break;
case 3:
System.out.println("Replace");
char a=(char)dts.readByte();
char b=(char)dts.readByte();
s2=s1.replace(a,b);
break;
case 4:
System.out.println("Trim");
s2=s1.trim();
break;
case 5:
System.out.println("Equals");
System.out.println("Enter another string to check equal:");
s2=dts.readLine();
eql=s1.equals(s2);
break;
case 6:
eql=s1.equalsIgnoreCase(s2);
break;
case 7:
System.out.println("Length");
int len=s1.length();
break;
case 8:
System.out.println("Char At");
System.out.println("Enter a position");
position=Integer.parseInt(dts.readLine());
char c=s1.charAt(position);
break;
case 9:
System.out.println("Compare To");
s2=dts.readLine();
int cmp=s1.compareTo(s2);
break;
case 10:
System.out.println("Concatenate");
s2=dts.readLine();
s3=s1.concat(s2);
break;
case 11:
System.out.println("Substring");
System.out.println("Enter a position");
position=Integer.parseInt(dts.readLine());
s2=s1.substring(position);
break;
case 12:
System.out.println("Value Of");
System.out.println("Enter a Integer");
position=Integer.parseInt(dts.readLine());
String.valueOf(position);
s3=s1+position;
break;
case 13:
System.out.println("To String");
System.out.println("Enter a Integer");
position=Integer.parseInt(dts.readLine());
String.valueOf(position);
s3=s1+position;
break;
case 14:
System.out.println("Index of");
ind=(char)dts.readByte();
index=s1.indexOf(ind);
break;
case 15:
System.out.println("Index of Positon");
System.out.println("Enter a position");
position=Integer.parseInt(dts.readLine());
index=s1.indexOf(ind,position);
System.out.println("Index of "+ind + " in "+ s1 +" is: "+index);
break;
default:
System.out.println("Wrong Choice");
break;
catch(Exception e)
System.out.println(e.getMessage());