error: incompatible types: unexpected return value Char compare to String

后端 未结 3 1250
眼角桃花
眼角桃花 2020-12-12 08:04

I am trying to compare char to a String but getting an error. Error

error: incompatible types: unexpected return value

code:



        
3条回答
  •  鱼传尺愫
    2020-12-12 08:51

    The main method can not return anything, it has a void type. You can write a separate function that returns that value, assign the value to a variable, or just print the value.

    public boolean strChar(String s, String p){
        return p.equals(new String(new char[]{c}));
    }
    

    or

    System.out.println(p.equals(new String(new char[]{c})));
    

    or

    boolean equals = p.equals(new String(new char[]{c}));
    

提交回复
热议问题