Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package twelvetwo;
- import java.util.Scanner;
- public class TwelveTwo {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int[] x = new int[] { 1, 2, 3 };
- int[] y;
- y = x; // not creating another array, copying a pointer x>>> [][][] <<<<
- // y
- y[1] = 313;
- System.out.println(x[1]); // 313 gets printed out
- x = new int[] { 2, 4 };
- y = x;
- y = new int[] { 2, 4 };
- y = x;
- y = new int[] { 2, 4 };
- int[] k = new int[] { 5, 7, 8, 9, 2 };
- int[] z = new int[] { 5, 7, 8, 9, 1 };
- if (ifequal(k, z))
- System.out.print("Equal arrays");
- else
- System.out.print("not Equal arrays");
- }
- public static boolean ifequal(int[] x, int[] y) {
- if (x.length != y.length) {
- return false;
- } else {
- for (int i = 0; i < x.length; i++) {
- if (x[i] != y[i])
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement