Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe how nerve cells communicate with other nerve cells.

Answered: 1 week ago