简体   繁体   中英

public static method howMany

I'm writing a public static method howMany , which takes as parameters an array of int s (nums) and an int (value) and returns an int (count) of how many times value occurs in nums .

My code:

public static int howMany(int[] nums, int value)
{
    int count = 0;

    for (int i = 0; i < nums.length; i++)
    {
        if (nums[i] == value);
        {
            count++;
        }
    }
    return count;
}

[The code is not working properly.] I've looked all over my code, I don't know what the issue could be.

if(nums[i] == value);

删除结尾的分号。

You have embedded the method in a class File, right? If Not, this might be the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM