This method must return a result of type boolean(Java)

前端 未结 3 1826
一整个雨季
一整个雨季 2021-01-26 12:14

this is my code.

boolean checkHit2() {
    if (cx < 0 || cx >= 640) {return true;}
    if (cy < ground[(int)cx]) {return false;}
    if (cx < blue +         


        
3条回答
  •  忘掉有多难
    2021-01-26 12:44

    This line:

    if (cx < blue + 15 && cx > blue - 15){ 
    

    Should be changed to

    if((cx < (blue + 15)) && (cx > (blue -15))){
    

    but I think you should move the comparation out like:

    int bluePlus = blue + 15;
    int blueMinus = blue - 15;
    if(cx < bluePlus && cx > blueMinus){
    

    EDIT: The error means that you miss to return boolean after all. After the if

    if(cx < bluePlus && cx > blueMinus){
    

    then you need to add return to the result. Please ignore the first comment.

提交回复
热议问题