Page 1 of 1

Exercise1:StringMethods Run the following code to check how String class Methods work, discuss with tutor, if you need e

Posted: Fri Apr 29, 2022 7:13 am
by answerhappygod
Exercise1:StringMethods Run the following code to check how
String class Methods work, discuss with tutor, if you need
explanation of any method. Make changes and try different
variations. String myString ="KOI classes are online in Term 122";
String s1= "NSW"; String s2= "nsw"; String s3 = " Welcome to NSW ";
System.out.println("Char at index 2(third char): " +
myString.charAt(2)); System.out.println("After Concat: "+
myString.concat("-Sadly-")); System.out.println("Checking equals
with case: " +s2.equals(s1)); System.out.println("Checking Length:
"+ myString.length()); System.out.println("Replace function: "+
myString.replace("is", "was")); System.out.println("SubString of
myString: "+ myString.substring(8)); System.out.println("SubString
of myString: "+ myString.substring(8, 12));
System.out.println("Converting to lower case: "+
myString.toLowerCase()); System.out.println("Converting to upper
case: "+ myString.toUpperCase()); System.out.println("Triming
string: " + s3.trim()); System.out.println("searching s1 in
myString: " + myString.contains(s1)); System.out.println("searching
s2 in myString: " + myString.contains(s2));