In: Computer Science
Requirements1. Name the java class (and filename) Week3_StringLab
.2. Print a welcoming message.
3. Ask user to enter a string. Use the nextLine() input method,
4. Use that string to test out at least 6 String methods, from the String class.
5. Of those 6, you must use these 3 methods: .split(), .indexOf (int ch), .subString (int beginningIndex).
6. Use 3+ other methods that you wish to try.
7. Print out the string BEFORE using each method
.8. Have the string processed by the method.
9. Print out an AFTER shot of the string, or any other data affected by the method.
10. Remember to use the same original data when testing each method.
In java please
import java.util.Scanner;
public class Week3_StringLab {
public static void main(String[] args) {
System.out.println("Welcome to Java");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.println("Before Split: " + str);
str.split(" "); // here it will split string into array of strings and returns array
// it will not make any changes
System.out.println("After Split: " + str);
System.out.println("Before indexOf: " + str);
str.indexOf('a'); // will return the index of char 'a'. it will not change string
System.out.println("After indexOf: " + str);
System.out.println("Before substring: " + str);
str.substring(2);// returns the substring in given range
System.out.println("After substring: " + str);
System.out.println("Before startsWith: " + str);
str.startsWith("a");// returns true if string starts with given string
System.out.println("After startsWith: " + str);
System.out.println("Before endsWith: " + str);
str.endsWith("a");// returns true if string ends with given string
System.out.println("After endsWith: " + str);
System.out.println("Before contains: " + str);
str.contains("aas");// returns true if string contains given string inside it
System.out.println("After contains: " + str);
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
Please Like and Support me as it helps me a lot