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

Write following Project in Java: Write a Java program that: Asks the user for 10

ID: 3751765 • Letter: W

Question

Write following Project in Java:

Write a Java program that: Asks the user for 10 numbers, and stores them in an array Calculates and prints the mode of those 10 numbers (recall that the mode is the most frequently occurring number in a list) If there is a tie for which element appeared the most, you may print any of those elements that are tied for the most Your program should use nested loops to find the mode. Your outer loop should go through each element in the array (cur is your current element), and your inner loop should count how many times cur appears in the array. Keep variables for the biggest count and the number corresponding to that biggest count, and update them if needed after counting the current array element. You should not use Java's Array.sort to sort the array Here is an example run of the program (user input is in red) Enter number: 2 Enter number:5 Enter number:4 Enter number:5 Enter number:6 Enter number:4 Enter number:9 Enter number:7 Enter number:4 Enter number: 2 Mode: 4

Explanation / Answer

ANSWER:-

import java.util.Scanner;

class NestedLoop {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in); // Reading from System.in

System.out.println("Enter 10 numbers: ");

int[] arr = new int[10];

int count,count1=0,bigcount=0;

for(int i=0;i<10;i++)

{

int n = reader.nextInt();

arr[i]=n;

}

for(int i=0;i<10;i++)

{

for(int j=i+1;j<10;j++)

{

if(arr[i]>arr[j])

{

int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

}

for(int i=0;i<10;i++)

{

count=1;

for(int j=i+1;j<10;j++)

{

if(arr[i]==arr[j])

count++;

}

if(count1<count)

{

count1=count;

bigcount=arr[i];

}

}

System.out.println("Mode="+bigcount);

}

}

// OUTPUT

Mode=4

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