Question

In: Computer Science

Requirements1. Name the java class (and filename) Week3_StringLab .2. Print a welcoming message. 3. Ask user...

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

Solutions

Expert Solution

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


Related Solutions

Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
In java, ask the user for a filename. Display the oldest car for every manufacturer from...
In java, ask the user for a filename. Display the oldest car for every manufacturer from that file. Files Given: car-list.txt car-list-1.txt car-list-2.txt car-list-3.txt (they are too big for question) Required Output: Standard Input                 Files in the same directory car-list-1.txt car-list.txt car-list-1.txt car-list-2.txt car-list-3.txt Enter filename\n Oldest cars by make\n Acura Legend 1989 2T1BPRHE8EC858192\n Audi 80/90 1988 2GKALMEK4E6424961\n Bentley Continental Flying Spur 2006 WBA3G7C5XFK430850\n BMW 600 1959 1N6AA0ED2FN639969\n Bugatti Veyron 2009 SCFEBBBC5AG474636\n Buick Century 1987 2HNYD18625H455550\n Cadillac DeVille 1994...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Following is hw14. Save the demo filename as lastname_hw14.java and the class name as lastname_people.java. Following...
Following is hw14. Save the demo filename as lastname_hw14.java and the class name as lastname_people.java. Following are three arrays each containing 50 values. Store all three arrays in the main method. Write an object to transfer the three arrays. int []age[] = {70, 68, 52, 69, 40, 59, 61, 34, 45, 50, 43, 22, 35, 50, 67, 33, 36, 22, 63, 65, 56, 31, 55, 28, 30, 24, 55, 35, 39, 59, 68, 50, 33, 45, 26, 54, 44, 56,...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT