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 4034376
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:57:52+00:00 2026-05-20T11:57:52+00:00

I wish to make a function that checks whether theres any number in the

  • 0

I wish to make a function that checks whether theres any number in the array that exist three or more times.

So example this array:

4 – 6 – 14 – 8 – 6 – 15 – 14 – 15 – 13
– 10 –

Shouldnt output anything, but this:

4 – 6 – 14 – 8 – 6 – 15 – 14 – 15 – 14
– 10 –

Should systemout print output that the number 14 exists three times.

How should this be done? I started making a for loop,

for(int i=0; i<array.length; i++){
}

And then I got stuck, how can i make this?

  • 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-05-20T11:57:52+00:00Added an answer on May 20, 2026 at 11:57 am
    for (int i = 0; i < array.length; i++) {
        int count = 0;
        for (int j = 0; j < array.length; j++) {
            {
                if (array[i] == array[j]) {
                    count++;
                }
    
            }
            if (count >= 3) {
                System.out.println(array[i] + " exists " + count
                        + " times.");
            }
        }
    }
    

    This programm outputs n times (for n >= 3) that the an element exists n times. You should add a logic that checks whether an element has already been checked. But maybe you can go on by yourself now. Hint: Use a HashMap or a List… or….

    Other solution that needs Integer[] instead of int[] and is faster:

    Integer[] array = new Integer[] { 1, 2, 1, 1, 1, 3, 3, 3, 2, 2, 4, 5 };
    
    for (int i = 0; i < array.length; i++) {
        int count = 0;
        if (array[i] != null) {
            int compare = array[i].intValue();
            for (int j = 0; j < array.length; j++) {
    
                if (array[j] != null) {
                    if (compare == array[j]) {
                        array[j] = null;
                        count++;
                    }
                }
    
            }
            if (count >= 3) {
                System.out
                        .println(compare + " exists " + count + " times.");
            }
        }
    }
    

    Output:

    1 exists 4 times.
    2 exists 3 times.
    3 exists 3 times.
    

    So copy your array into a Integer[] array first. The latter algorithm fixes also the problem with the output.

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

Sidebar

Related Questions

I wish to test a function that will generate lorem ipsum text, but it
I have a large system that I have coded and I wish to make
In C# I sometimes wish I could make special methods for certain instantiations of
I wish Subversion had a better way of moving tags. The only way that
I wish to implement my software on a shareware basis, so that the user
I wish to perform an experiment many different times. After every trial, I am
EDIT: Thanks guys - perfect! I wish I could check more than one answer,
I am trying to create a function that will block access to some of
I'm trying to build a function that will show me all path's where a
when user insert text input i wish get, and insert in link. How that

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.