Advertisement
Omar_Natour

Natour, O. in class

Dec 2nd, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package twelvetwo;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TwelveTwo {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.  
  10.         int[] x = new int[] { 1, 2, 3 };
  11.         int[] y;
  12.  
  13.         y = x; // not creating another array, copying a pointer x>>> [][][] <<<<
  14.                 // y
  15.         y[1] = 313;
  16.         System.out.println(x[1]); // 313 gets printed out
  17.  
  18.         x = new int[] { 2, 4 };
  19.         y = x;
  20.  
  21.         y = new int[] { 2, 4 };
  22.         y = x;
  23.         y = new int[] { 2, 4 };
  24.  
  25.         int[] k = new int[] { 5, 7, 8, 9, 2 };
  26.         int[] z = new int[] { 5, 7, 8, 9, 1 };
  27.  
  28.         if (ifequal(k, z))
  29.             System.out.print("Equal arrays");
  30.         else
  31.             System.out.print("not Equal arrays");
  32.  
  33.     }
  34.  
  35.     public static boolean ifequal(int[] x, int[] y) {
  36.  
  37.         if (x.length != y.length) {
  38.             return false;
  39.         } else {
  40.             for (int i = 0; i < x.length; i++) {
  41.                 if (x[i] != y[i])
  42.                     return false;
  43.  
  44.             }
  45.             return true;
  46.  
  47.         }
  48.  
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement