Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Algorithm1{
- public static void main (String[] args){
- int[] array1 = {1, 2, 3};
- int[] array2 = {1, 2, 3, 4, 5, 6};
- int matchCount = 0;
- boolean match = false;
- for(int j = 0; j < array1.length;j++) {
- for(int i = 0; i < array2.length;i++){
- if(array1[j] == array2[i])
- matchCount++;
- }
- }
- if(matchCount >= array1.length && matchCount >= array2.length)
- match = true;
- if(match = true){
- System.out.println("The data in the arrays is the same.");
- }
- else if(match = false){
- System.out.println("The data in the arrays is different.");
- }
- }
- }
- if(match = true) {
- System.out.println("The data in the arrays is the same.");
- }
- if(match = true){
- System.out.println("The data in the arrays is the same.");
- }
- else if(match = false){
- System.out.println("The data in the arrays is different.");
- }
- if(match == true){
- System.out.println("The data in the arrays is the same.");
- }
- else if(match == false){
- System.out.println("The data in the arrays is different.");
- }
- if(match){
- System.out.println("The data in the arrays is the same.");
- }
- else{
- System.out.println("The data in the arrays is different.");
- }
- import java.io.*;
- import java.util.Arrays;
- class Ideone
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- int[] array1 = {1, 2, 3, 6, 5, 4, 3};
- int[] array2 = {1, 2, 3, 4, 5, 6, 4, 4,6};
- java.util.Arrays.sort(array1);
- java.util.Arrays.sort(array2);
- boolean match = true;
- int ptr1 = 0;
- int ptr2 = 0;
- while(ptr1<array1.length && ptr2<array2.length && array1[ptr1]==array2[ptr2])
- {
- ptr1++;ptr2++;
- while(ptr1<array1.length && array1[ptr1]==array1[ptr1-1])
- {
- ptr1++;
- }
- while(ptr2<array2.length && array2[ptr2]==array2[ptr2-1])
- {
- ptr2++;
- }
- }
- if((ptr1 == array1.length) && (ptr2 == array2.length))
- System.out.println("The data in the arrays is the same");
- else
- System.out.println("The data in the arrays is the different");
- }
- }
- public int findArray(Integer[] arg1, Integer[] arg2)
- {
- return Collections.indexOfSubList(Arrays.asList(arg1), Arrays.asList(arg2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement