public static void main(String[] args) { int[] array1= {4,2,3,1,2,1}; int[] array2 = {2,3,1}; System.out.print(contain(array1, array2)); } public static boolean contain(int[] array1, int[] array2) { int counter =0; for(int i=0; i<(array1.length-array2.length); i++) { counter =0; for(int j=0; j<array2.length; j++) { if(array1[i+j] == array2[j]) counter ++; else break; } if(counter == array2.length) return true; } return false; } } //OUTPUT: true.
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter