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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:40:27+00:00 2026-05-31T15:40:27+00:00

I’m having trouble passing an array between methods and have excerpted my code below.

  • 0

I’m having trouble passing an array between methods and have excerpted my code below.

I’ve successfully created two arrays, computerDice and humanDice, and now I need to count the number of ones, twos, threes, etc in each array. See example below the code. I’ve validated that a.) that the input arrays contain valid data and b.) the counter works properly.

However, now I’m trying to return occurences as an array–six distinct values of occurence representing ones, twos, threes, etc. in the array being SENT to the method–and have been unsuccessful. I keep having issues with my occurence return…incompatible types, bad operand typed for operand +…and I get something different with each thing I try. I’m obviously missing something with how to cast/populate this variable.

NOTE: This is homework; I’m just trying to grasp my conceptual mis-steps.

// SEND VALUES TO numToFind AND CREATE SCORING ARRAY FOR computerDice AND humanDice
        for(int i=1;i<7;i++)
        {
            int[] pipCountsComputer = findVals(computerDice,i);
            int[] pipCountsHuman = findVals(humanDice,i);
            System.out.println(i + " " + pipCountsComputer + " " + pipCountsHuman);
        }
    }
//
// COUNT INSTANCES OF numToFind IN arr[] AND RETURN THE occurence
    public static int[] findVals(int[] arr, int numToFind)
    {
        int[] occurence=0;
        for (int i = 0; i < arr.length; i++)
        {
            if (arr[i] == numToFind)
                occurence = occurence+1;
        }
        return occurence;
    }

I’ve already validated that, for example, given computerArray = 52334 and humanArray = 11163 my print statement yields:

1 0 3 (ones, computer has 0 ones, human has 3 ones)
2 1 0 (twos, computer has 1 two, human has 0 twos)
3 2 1 etc.
4 1 0 My desired arrays for this dataset would be:
5 1 0 pipCountsComputer{0,1,2,1,1,1}
6 0 1 pipCountsHuman{3,0,1,0,0,1}

  • 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-31T15:40:28+00:00Added an answer on May 31, 2026 at 3:40 pm

    If I understood correctly, try this for counting the number of occurrences:

    public static int findVals(int[] arr, int numToFind) {
        int occurence = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == numToFind)
                occurence++;
        }
        return occurence;
    }
    

    I really don’t understand why you want to return an array, an occurrence is just a number.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.