how to return 2 values from a java function?

Posted by javaLearner.java on Stack Overflow See other posts from Stack Overflow or by javaLearner.java
Published on 2010-05-14T07:22:49Z Indexed on 2010/05/14 7:24 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

Here is my code:

// Function code
public static int something(){
    int number1 = 1;
    int number2 = 2;
    return number1, number2;
}

// Main class code
public static void main(String[] args) {
  something();
  System.out.println(number1 + number2);
}

Error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
    at assignment.Main.something(Main.java:86)
    at assignment.Main.main(Main.java:53)

Java Result: 1

© Stack Overflow or respective owner

Related posts about java

Related posts about function