Question: JAVA / Matcher / Regex / easy When starting the program, the user must enter two sentences . After the program should: *remove spaces in

JAVA / Matcher / Regex / easy

When starting the program, the user must enter two sentences. After the program should:

*remove spaces in each of the lines

*change case of all letters to lower

*using the Matcher class to determine the index of the string match

*determine if all characters in the second sentence are letters

Example of input: hEllO woRld and World Program result: 5 true

Partial code provided:

public class Main {
public static void main(String[] args) {
String s1 = "hEllO woRld"; String s1 = "World"
s1 = sentence1.replaceAll(" ", "").toLowerCase(); s2 = sentence2.replaceAll(" ", "").toLowerCase();

//PLEASE ADD CODE PART HERE using the Matcher class to determine the index of the string match

boolean letters = s2.matches("[a-zA-Z]+");

//here goes output - no problem on this.

}

} 

And yes, on both provided string's output should be 5. How to obtain value 5 by using Matcher class?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!