Question: Complete the mode method which returns the number that appears the most often in the array. However, you should first complete the count method that

 Complete the mode method which returns the number that appears the

Complete the mode method which returns the number that appears the most often in the array. However, you should first complete the count method that returns the number of times num appears in the array. Then use the count method to help write the mode method. Each method needs only one loop.

Note.

(1) The array will have at least one element.

(2) There will only be one mode per array.

public class Main public static void main(String[] args) { int [] a = { 5, 6, 7, -2, -2, 0, 6, 4, 6 }; System.out.println( mode( a ) ); // 6 appears the most times int [] b = { -4, 0, 0, -4, -4, 7, -11, -4, -4 }; System.out.println( mode( b ) ); // -4 appears the most times } public static int mode( int [] a ) { // return the number that appears the most often in the array (i.e. the mode) // use the count method to help write this method // the array will have a length of one or more // the array has only one mode } public static int count( int [] a, int num) { // return the number of times num appears in the array // the array will have a length of one or more }

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!