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

A mode in an array numArray of numbers is thenumber that appears most often ? Yo

ID: 3654262 • Letter: A

Question

A mode in an array numArray of numbers is thenumber that appears most often

? You task is to first ask the user to input a numberN, which indicates the size of numArray

? Next you need to generate N random integers inrange 1 to 100, store them in numArray, and print

their values on the screen.

? Then you pass numArray into the following methodwhich finds the mode of an array and print the

result in the main method:

public static int findMode(int[] array)


Hint:

? An array could have more than 1 modes, but

in this exercise, you can find any of those

? You can sort the array first and then go

through the array just once to find the mode

? Use java.util.Arrays.sort(numArray) to sort


Sample running result:

Please input the size of the array:20

The array is:

64 38 69 100 38 81 45 46 58 14 46 66 46 54 84

72 52 46 13 70

The sorted array is:

13 14 38 38 45 46 46 46 46 52 54 58 64 66 69 70

72 81 84 100

The mode is:46


Explanation / Answer

class sorting
{
public static void main(String[] input)
{
int k=input.length;
String temp=new String();
String names[]=new String[k+1];
for(int i=0;i<k;i++)
{
names[i]=input[i];
}
for(int i=0;i<k;i++)
for(int j=i+1;j<k;j++)
{
if(names[i].compareTo(names[j])<0)
{
temp=names[i];
names[i]=names[j];
names[j]=temp;
}
}
System.out.println(“Sorted order is”);
for(int i=0;i<k;i++)
{
System.out.println(names[i]);
}
}

please rate

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