Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Main Page Problems Solve a Problem egualsStrings Show Header O BJP4 Self-Check 7

ID: 3819728 • Letter: M

Question

Main Page Problems Solve a Problem egualsStrings Show Header O BJP4 Self-Check 7.16a: countStrings Favorite Java amas Strings Marty Stepp (on 2016/0908) Write a method countstrings that takes an array of strings and a target String and returns the number of occurences target appears in the amay Type your solution here: public static int countstrings (Stringl] list, String target) This is a method problem Write a Java method as described. Donot write a complete program orclassk just the method above. 4 Indent f Submit Sound FX Highlighting you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or nstructor7 lf something seems wrong with the site lerrors, slow performance, incorrect problemstests, etc.), please contact us. 44 n

Explanation / Answer

   public static int countStrings(String[] list, String target) {
       int count = 0;
       // for each string.. check if string is equal to target
       // if yes, increase the count
       for(String s: list) {
           if(s.equals(target))
               count++;
       }
       return count;
   }
  
   public static boolean equalsStrings(String[] list1, String[] list2) {
       // if both list don't have equal number of strings
       if(list1.length != list2.length)
           return false;
      
       // get total length
       int length = list1.length;
      
       for(int i=0; i<length; i++) {
           // check if same string is present in both the lists
           // at same index.. if not return false
           if(!list1[i].equals(list2[i]))
               return false;
       }
      
       // return true
       return true;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote