简体   繁体   English

公共静态方法

[英]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 . 我正在写一个public static方法howMany ,其作为参数的阵列int S(NUMS)和int (值),并返回一个int的多少次(计数) value在发生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? 您已将该方法嵌入到File类中,对吗? If Not, this might be the issue. 如果不是,则可能是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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