fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // same first element (1), all other elements are different = different arrays
  13. int[] a = {1, 5, 6, 7};
  14. int[] b = {1, 9, 8, 4};
  15.  
  16. if(equalArrays(a, b)) {
  17. System.out.println("a and b are equal");
  18. } else {
  19. System.out.println("a and b are not equal");
  20. }
  21.  
  22.  
  23. // same third element (6), all other elements are different = different arrays
  24. int[] c = {3, 5, 6, 7};
  25. int[] d = {1, 9, 6, 4};
  26.  
  27. if(equalArrays(c, d)) {
  28. System.out.println("c and d are equal");
  29. } else {
  30. System.out.println("d and c are not equal");
  31. }
  32. }
  33.  
  34. public static boolean equalArrays(int [] a, int [] b) {
  35. if(a.length == 0 && b.length == 0)
  36. return true;
  37. else {
  38. if(a.length == b.length)
  39. for(int i = 0; i < a.length ; i++)
  40. if (a[i]==b[i])
  41. return true;
  42. }
  43. return false;
  44. }
  45. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
a and b are equal
c and d are equal