Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

11,402 questions

15,552 answers

573 users

How to return array from a method in Java

2 Answers

0 votes
public class MyClass {
    static int[] f_arr() {  
        return new int[]{1, 2, 3, 4, 5, 6};  
    }  
    public static void main(String args[]) {
        int arr[] = f_arr();  
        
        for (int i = 0; i < arr.length; i++) { 
            System.out.println(arr[i]);  
        }  
    }
}


/*
run:

1
2
3
4
5
6

*/

 




answered May 29 by avibootz
0 votes
public class MyClass {
    public static int[] reverse(int[] arr) { 
        int[] rev = new int[arr.length];
        
        for (int i = 0, j = rev.length - 1; i < arr.length; i++, j--) { 
            rev[j] = arr[i]; 
        }
        return rev;
    }
    public static void main(String args[]) {
        int[] arr1 = {1, 2, 3, 4, 5};
        int[] arr2 = reverse(arr1);
        
        for (int i = 0; i < arr2.length; i++) { 
            System.out.print(arr2[i] + " ");
        }
    }
}


/*
run:

5 4 3 2 1 

*/

 




answered Jul 11 by avibootz
...