WeiJie Lim wrote:System.out.println("11"); is causing error of "unreachable statement" because a method can only have one statement that returns something ?
No. The System.out.println statement is after the return statement, so that it will never be executed. The compiler detects this and gives you an error.
WeiJie Lim wrote:In this case, there are two statements that return something, return sc.nextInt(); and System.out.println("11"); .
No. The System.out.println statement prints something on the console, but it is not a statement that returns a value from the method. Only with the "return" keyword you can return a value from a method.
Printing something on the console and returning a value from a method are two totally different things. Why do you think that a System.out.println method returns anything from a method?