有关代码HS项目的Java问题“坏苹果”

发布于 2025-01-23 00:31:55 字数 745 浏览 2 评论 0原文

我不断遇到解释错误,我仍然是编码的新手,因此,如果有人可以帮助我修复它,并解释了为什么它不起作用,那么代码的目标是返回数组中有多少字符串,其中有大写字母。

public int badApples(String[] apples)
{
    int holdo = 0;
    
    for(int i = 0; i < apples.length; i++)
    {
        for(int c = 0; c < apples[i].length(); c++)
        {
            if((apples[i].charAt(c)).isUpperCase)
            {
                holdo++;
            }
        }
    }
    
    return holdo;
    
}

收到的错误:

quicktest.java:19: error: char cannot be dereferenced
            if((apples[i].charAt(c)).isUpperCase)
                                    ^
quicktest.java:19: error: illegal parenthesized expression
            if((apples[i].charAt(c)).isUpperCase)
              ^

I keep getting a dereference error, I am still new to coding so if anyone could help me fix it, and explain why it didn't work, the goal of the code was to return how many strings in an array had a capital letter.

public int badApples(String[] apples)
{
    int holdo = 0;
    
    for(int i = 0; i < apples.length; i++)
    {
        for(int c = 0; c < apples[i].length(); c++)
        {
            if((apples[i].charAt(c)).isUpperCase)
            {
                holdo++;
            }
        }
    }
    
    return holdo;
    
}

Errors Received:

quicktest.java:19: error: char cannot be dereferenced
            if((apples[i].charAt(c)).isUpperCase)
                                    ^
quicktest.java:19: error: illegal parenthesized expression
            if((apples[i].charAt(c)).isUpperCase)
              ^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2025-01-30 00:31:55

如果您不使用自动完成,语法突出显示等的IDE,那么这样的错误是很

常见(苹果[i] .charat(c))返回。是一个对象,哪个类? (字符串?),还是像intcharboolean之类的原始性?

那时,您会收到错误,您正在尝试引用成员字段isuppercase。返回的类型支持它吗?您可以访问它吗?

有时,还有其他类别的其他类别的实用程序方法,您可以调用这些方法以获取有关参数中传递的信息,例如targin.isuppercase()

Errors like this are quite common if you don't use an IDE with autocompletion, syntax highlighting etc. Therefore I just give hints, so you can learn how to help yourself in similar problems in the future:

Try to find out, what type does (apples[i].charAt(c)) return. Is it an object, which class? (String?) Or is it a primitive like int, char, boolean?

At that point you get the error, you are trying to reference the member field isUpperCase. Does the returned type support it? Are you allowed to access it?

Sometimes there are so called utility methods of other classes that you can call to get information about the passed in parameter, like Character.isUpperCase().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文