0

People of Earth ,Can someone Help?

Hi humans ! how i can return two variables in this code public class Program { int gar(int x,int m,int h){ x *= 2 ; return array [x,m,h]; } public static void main(String[] args) { int x =5; int m = 12; int h = 2019; gar(x,m,h); System.out.println(m,x,h); } }

11th Jul 2020, 6:58 PM
Khaled Almutairi
2 Answers
+ 2
In java, it won't possible to return more than one element. So you have use a datastructure or array to return multiple values... Or for simple codes, form to a string and on return extract back again..
11th Jul 2020, 7:01 PM
Jayakrishna 🇼🇳
+ 2
method 1. use a global variable to change the values easily. method 2. yes it's actually possible to return more than one values with arrays. import java.util.Arrays; public class Program { public static int gar(int x,int m,int h){ x *= 2 ; return new int[] {x,m,h}; } public static void main(String[] args) { int x =5, m = 12, h = 2019; int[] arr = gar(x,m,h); System.out.println(Arrays.toString(arr)); } }
11th Jul 2020, 8:20 PM
Shen Bapiro
Shen Bapiro - avatar