+ 2
How to return two values from a function?
We know that the function execution terminates after the first return expression, then how can I return two values?
6 ответов
+ 7
To solve this problem you can return a new instance of a static class with several fields.
+ 2
You can return the array of values. Any number of one type values.
I have finished just this example in "My codes" ;)
+ 1
But how to return array please send a snippet
+ 1
Just one step separates you from example code in my profile, but it is no problem:
public class Solution {
public static void main(String[] args) throws Exception {
String names[] = getnames();
System.out.println(names[0]+" + "+names[1]+" + "+names[2]+" = Object-oriented programming!");
}
public static String[] getnames() throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] name = new String[3];
for (int i=0;i<3;i++) {
name[i]=reader.readLine();
}
return name;
}
}
+ 1
Thank you very much
0
you can't.