3
answers
0
watching
410
views
31 Dec 2017
3. Consider the following method, which returns the number of times the parameter String word occurs in the parameter array wordArray: public static int countOccurrences (String[] wordArray, String word) { int result; result = 0; for (int i = 0; i < wordArray.length; i++) { if (wordArray[i] == word) { result = result + 1; return result; Unfortunately, the above method contains a bug. This bug causes the method to return 0 instead of the expected value of 2 when it is called in the following code fragment: String[] animalism = { new String ("four"), new String ("legs"), new String ("good"), new String ("two"), new String ("legs"), new String ("bad") }; int count = count Occurrences (animalism, "legs"); System.out.println("Number of occurrences: " + count); Describe what the problem is, and suggest a simple way to fix it. BE BRIEF; overly long answers will be grounds for mark deductions.
3. Consider the following method, which returns the number of times the parameter String word occurs in the parameter array wordArray: public static int countOccurrences (String[] wordArray, String word) { int result; result = 0; for (int i = 0; i < wordArray.length; i++) { if (wordArray[i] == word) { result = result + 1; return result; Unfortunately, the above method contains a bug. This bug causes the method to return 0 instead of the expected value of 2 when it is called in the following code fragment: String[] animalism = { new String ("four"), new String ("legs"), new String ("good"), new String ("two"), new String ("legs"), new String ("bad") }; int count = count Occurrences (animalism, "legs"); System.out.println("Number of occurrences: " + count); Describe what the problem is, and suggest a simple way to fix it. BE BRIEF; overly long answers will be grounds for mark deductions.
3
answers
0
watching
410
views
For unlimited access to Homework Help, a Homework+ subscription is required.
22 Jun 2023
kibettitus2020Lv10
16 Nov 2022
Already have an account? Log in
Nelly StrackeLv2
3 Jan 2018
Already have an account? Log in