Read more: http://cheater-handal.blogspot.com/2011/05/cara-membuat-ucapan-selamat-tinggal-di.html#ixzz2VzHob9hY Contoh Program Java (Past by Reference) | NOTE FOR LIFE

Contoh Program Java (Past by Reference)

Listing 1
public class testreference {
     public static void main(String[] args) {
    int ages[] = {17, 21, 27};
                        for (int i=0; i<ages.length; i++){
                            System.out.println(ages[i]);
                        }
                        test(ages);
                        for (int i=0; i<ages.length; i++){
                            System.out.println(ages[i]);
                        }
                    }
                    public static void test(int arr[]){
                        for (int i=0; i<arr.length; i++)
                            arr[i] = i + 60;
                    }

                }
Output 1

Listing 2
public class testreference {
     public static void main(String[] args) {
    int nomor[] = {6, 13, 27};
                        for (int i=0; i<nomor.length; i++){
                            System.out.println(nomor[i]);
                        }
                        test(nomor);
                        for (int i=0; i<nomor.length; i++){
                            System.out.println(nomor[i]);
                        }
                    }
                    public static void test(int arr[]){
                        for (int i=0; i<arr.length; i++)
                            arr[i] = i + 50;
                    }
                }
Output 2


0 komentar:

Posting Komentar