Menu

[Solved]-Two Main Method Base Method Search Matchergroup Return Array Main Method Want Iterate Sent Q37259690

I have two main method. The base() method will searchmatcher.group() and return in array. in main method I want toIterate that sent from the base() method. However, when I doIterate in main method I only printout “John Writes”. I supposed toprintout all that start by John – which they are “JohnWrites”,”John Doe”, “John Mayne”. I would apperciate any help.

public class calculate {
  
   public static void main(String[] args) {

       for(String x:calculate.base()){
          System.out.println(x);
       }
   }
   public static String[] base() {

   String text =
   “John writes about this, and John Doe writes aboutthat and John Wayne writes about everything.”;
  
   String patternString1 = “(John) (.+?) “;

   Pattern pattern =Pattern.compile(patternString1);
   Matcher matcher = pattern.matcher(text);

   while(matcher.find()) {
      
       String fx = matcher.group();
  
           String total []= fx.split(” “);
             
           returntotal;
  
   }
   String[] no = { “Error” };
           return no;
   }
}

Expert Answer


Answer to I have two main method. The base() method will search matcher.group() and return in array. in main method I want to Iter… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *