Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:49:33+00:00 2026-06-15T00:49:33+00:00

I was assigned a programming problem for homework, and I am at a stand-still.

  • 0

I was assigned a programming problem for homework, and I am at a stand-still. I have searched for hours today trying to find an answer, and it seems like it’s never been asked on here. I basically need to find the reverse of the mode of the array. Here is the question I was asked to find the solution to:

LeastFrequent – Output the integer which occurs least frequently along
with its occurrence count from a list of 10 integers input from
System.in. If multiple integers in the list occur least frequently,
output any integer that occurs least frequently. Name your class
LeastFrequent. You can assume that all 10 integers are in the range
-100 to 100 inclusive.

Here is the code I have so far:

package leastfrequent;
import java.util.*;

public class LeastFrequent
{
    private static int[] arr = new int[10];
    private static int minValue;
    private static int minCount;

    public static void leastCommon()
    {
        for(int i = 0; i < arr.length; i++)
        {
            int count = 0;

            for(int j = 0; j < arr.length; j++)
            {
                if(arr[j] == arr[i]) 
                {
                    count++;
                }
            }

            if(count > minCount)
            {
                minCount = count;
                minValue = arr[i];
            }
        }
    }

    public static void main(String[] args)
    {
        Scanner stdin = new Scanner(System.in);
        System.out.print("numbers: ");

        for(int i = 0; i < arr.length; i++)
        {
            arr[i] = stdin.nextInt();
        }

        Arrays.sort(arr);
        leastCommon();

        System.out.println("least frequent: " + minValue + " occurs " + minCount + " times");
    }
}

Basically I figured if I could find the mode, I could reverse that algorithm and find the least common, but that doesn’t work because it always reads zero.

Does anyone have any ideas?

Please help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:49:34+00:00Added an answer on June 15, 2026 at 12:49 am

    Two changes:

    1. Initialize minCount with biggest index i.e. 10 as:

      private static int minCount = 10;
      
    2. Change the if to compare against less than in place of greater than as:

      if(count < minCount){
      

    This way you will change the minCount with lower count, whenever you receive the lower occurence count and in the end, it will have the least.

    I think, rest is fine. Hope this fixes your program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Strange programming problems as of now..As you can see below i have assigned intFrontPtr
I was practicing the dynamic programming problem on SPOJ. But I have no idea
I have been assigned to implement an interface to an API that uses XML
I have assigned 5000 ms to Settimeout but it is executing before assigned time
I have assigned a custom data attribute to some circles added to the Raphael
I have been assigned wit the task to write a program that takes a
I have four UINavigationControllers assigned each to a tab in a UITabBarController. Each UINavigationController
Background: I have a design pattern problem that I was hoping someone may be
I was assigned the following project for my VB.Net programming course: Write a program
Unlike programming languages, SQL doesn’t allow variable to be assigned a value using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.