public class MainClass{
public static void main(String args[]) {
String s = " This is a test for Java";
System.out.println(s);
System.out.println(s.toUpperCase());
System.out.println(s.toLowerCase());
System.out.println("["+s+"]");
s=s.trim();
System.out.println("["+s+"]");
s=s.replace('J','X');
s=s.replace('C','Y');
s=s.replace('2','Z');
System.out.println(s);
int i1 = s.indexOf('X');
int i2 = s.indexOf('Y');
int i3 = s.indexOf('Z');
char ch[] = s.toCharArray();
ch[i1]='J';
ch[i2]='C';
ch[i3]='2';
s = new String(ch);
System.out.println(s);
}
}
This is a test for Java
THIS IS A TEST FOR JAVA
this is a test for java
[ This is a test for Java]
[This is a test for Java]
This is a test for Xava
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at MainClass.main(MainClass.java:19)