Void methods cannot return a value

前端 未结 10 2303
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 01:38

I\'m following the CS106A lectures online. I\'m going through the code on Lecture 12, but it\'s giving me errors in Eclipse.

This is my code. It seems the error is beca

10条回答
  •  半阙折子戏
    2021-01-23 01:52

    Because You have added ; at the end of an method

    corrected Code:

    public class CS106A {
    
    public static void main(String[] args){
    Char char=new CS106A.toLower('s');
    System.out.println(char);
    }
    
    public char toLower(char ch)
    {
        if (ch >= 'A' && ch <= 'Z'){
            return ((ch - 'A') + 'a');
        }
        return ch;      
    }
    }
    

    Please Read how to write Methods in java on any java website

提交回复
热议问题