Void methods cannot return a value

前端 未结 10 2182
爱一瞬间的悲伤
爱一瞬间的悲伤 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:44

    Yes void return type can not return any value.

    It will be better if you create a separate function for this process which will return some value and call it from main().

    public class Test
    {
        public static void main(String[] args)
        {
            String[] a = testMethod();
        }
    
        public String[] testMethod()
        {
            .....
            .....
            return xx;
        }
    }
    

    Hope it will help you.

    Thanks

提交回复
热议问题