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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply