java - 尝试编译代码但不断收到相同的错误?

标签 java

我不断收到错误:“缺少返回语句。”我的返回声明不是列出了 5 次吗?有谁知道我为什么会遇到这个问题以及如何解决它?它指的是倒数第二个括号。任何关于为什么会发生这种情况的帮助/想法都值得赞赏。谢谢。

public class words
    {
        // instance variables - replace the example below with your own
        private String w;

        /**
         * Default Constructor for objects of class words
         */
        public words()
        {
            // initialise instance variables
            w="";
        }

        /**
         * Assignment constructor
         */
        public words(String assignment)
        {
            w=assignment;
        }

        /**
         * Copy constructor
         */
        public words(words two)
        {
            w=two.w;
        }

        /**
         * Pre: 0<=i<length( )
         * returns true if the character at location i is a vowel (‘a’, ‘e’, ‘i', ‘o’, ‘u’ only), false if not
         */
        private boolean isVowel(int i)
        {
            if (w.charAt(i)=='a')  
            return true; 
            else if (w.charAt(i)=='e')
            return true;
            else if (w.charAt(i)=='i')
            return true;
            else if (w.charAt(i)=='o')
            return true;
            else if (w.charAt(i)=='u')
            return true;
        }

    }

最佳答案

告诉我,如果 w.charAt(i) 是“b”,您会返回什么。 您需要添加最后一行:

private boolean isVowel(int i)
        {
            if (w.charAt(i)=='a')  
            return true; 
            else if (w.charAt(i)=='e')
            return true;
            else if (w.charAt(i)=='i')
            return true;
            else if (w.charAt(i)=='o')
            return true;
            else if (w.charAt(i)=='u')
            return true;
            else return false;
        }

关于java - 尝试编译代码但不断收到相同的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976205/

相关文章:

java - 在 robotsium 脚本中使用 Rosource Id 单击按钮

java - 进程间共享线程

java - 在 libgdx java 中运行时旋转粒子

java - 使用 Hibernate 5 和 Spring 4 的程序化 SchemaExport/SchemaUpdate

java - 自定义插件扩展中的嵌套对象

java - 使用 directjngine 在 ext-js 中无限滚动

java - Google Drive API 是否允许我们无需身份验证即可下载公共(public)文件?

java - 如何使用 gradle 使 GitLab CI 发布 Spring Boot JAR?

java - Eclipse 打开项目中包含的文件

java - @DataProvider 和@BeforeMethod 命令