小编Bos*_*jin的帖子

我的方法不能返回布尔值

我是java的新手.

这是我的代码:

public boolean endsLy(String str) {
  if(str.length()>=2){
    if(str.substring(str.length()-2).equals("ly")) return true;
  }
  else return false;
}
Run Code Online (Sandbox Code Playgroud)

但编译器给出:

Error:  public boolean endsLy(String str) {          
This method must return a result of type boolean
Run Code Online (Sandbox Code Playgroud)

可能的问题:if语句结构理论上可以允许运行到达方法的末尾而不调用return.
考虑在方法中添加最后一行返回some_value; 所以总是返回一个值.

java

0
推荐指数
1
解决办法
328
查看次数

我怎样才能扩展2个班级

我想扩展2个课程,但我不知道如何,我知道这是非常愚蠢的问题,但我需要它.

我想这样做,但这是不可能的.我可以用哪种方式做到这一点?

Public class Mclass extends Fragment extends extends ListActivity
{

}
Run Code Online (Sandbox Code Playgroud)

谁能帮我 ?谢谢

java inheritance android

0
推荐指数
1
解决办法
782
查看次数

不存在的错误

嗯.这很尴尬但我得到一些错误,说的是完全不真实的东西.

有人可以给我一个如何解决它的建议.我是java的新手,所以简单的答案是最好的.

谢谢.

 public class Project1
    {
    public static void main( String [] args )
    {
        System.out.println();
        String output = new String();
        String inital = new String();
        inital = english_to_morse();

        for( int k = 0; k < inital.length(); k++)
        {
            output += morse(inital.charAt( k ));
        }

            System.out.print(output);
            System.out.println();
    }
        public static void choice()
    {
        int user_choice = 0; ///This is the method giving me grief!!!!!!
        user_choice = Input.getInt("Enter 1 if you want to change English to Morse code, and enter …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
65
查看次数

使用joptionpane退出程序

我有一个gui java程序,它计算文件夹中的文件数(如果有的话),并将它们的名字存储在一个数组中进行处理.在没有可供处理的文件的情况下,我想显示一个joptionpane,其中显示消息"没有文件可供处理.请单击退出按钮退出系统".

当用户单击joptionpane的按钮时,如何退出系统?就像是

if (array.length == 0){
    JOptionPane.show .......
    {
        System.exit(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

java swing joptionpane

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×4

android ×1

inheritance ×1

joptionpane ×1

swing ×1