我不断收到错误:“缺少返回语句。”我的返回声明不是列出了 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/