How to output same numbers from previously defined two different integer arraysSymmetric difference of two Java arraysHow can I concatenate two arrays in Java?How to initialize all members of an array to the same value?A Java collection of value pairs? (tuples?)How can I create a two dimensional array in JavaScript?How to sort an array of integers correctlyHow to get the difference between two arrays in Javascript?How to merge two arrays in JavaScript and de-duplicate itemsHow to remove item from array by value?How do I remove a particular element from an array in JavaScript?remove number from array

What are good ways to spray paint a QR code on a footpath?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Getting geometries of hurricane's 'cone of uncertainty' using shapely?

Does anyone know what these symbols mean?

What's the safest way to inform a new user of their password on my web site?

Spicket or spigot?

Inquiring about the possibility of a job

Wrong corporate name on employment agreement

Can 'leave' mean 'forget'?

Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?

How would an order of Monks that renounce their names communicate effectively?

Generate and graph the Recamán Sequence

How to fix a dry solder pin in BGA package?

Why does a brace command group need spaces after the opening brace in POSIX Shell Grammar?

Is it allowed to spend a night in the first entry country before moving to the main destination?

Should I report a leak of confidential HR information?

Why are there so many religions and gods?

Reverse of diffraction

Why did this meteor appear cyan?

Averting Real Women Don’t Wear Dresses

Did Wakanda officially get the stuff out of Bucky's head?

Symbol for "not absolutely continuous" in Latex

Different budgets within roommate group

Why don't all electrons contribute to total orbital angular momentum of an atom?



How to output same numbers from previously defined two different integer arrays


Symmetric difference of two Java arraysHow can I concatenate two arrays in Java?How to initialize all members of an array to the same value?A Java collection of value pairs? (tuples?)How can I create a two dimensional array in JavaScript?How to sort an array of integers correctlyHow to get the difference between two arrays in Javascript?How to merge two arrays in JavaScript and de-duplicate itemsHow to remove item from array by value?How do I remove a particular element from an array in JavaScript?remove number from array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I need to write a program which defines two arrays of ints and prints all elements of the first array which do not appear in the second, but each value once only, without repetitions (the order of printed values is irrelevant).
For example for arrays



 int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
int[] brr = 2,3,6,8,1,5 ;



the result could be :
7 4 9




It can be used only java.lang. package. It can't be created any arrays, collections or Strings.










share|improve this question
























  • This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

    – RahlSK
    Mar 25 at 12:38






  • 3





    What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

    – jwismar
    Mar 25 at 12:38











  • You can do it by iterating through arr and brr

    – MjM
    Mar 25 at 12:41












  • Yep, definitely, numbers that are defined in array 1, but not in array 2

    – Mark Ladyshev
    Mar 25 at 12:49











  • No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

    – Mark Ladyshev
    Mar 25 at 12:52

















-1















I need to write a program which defines two arrays of ints and prints all elements of the first array which do not appear in the second, but each value once only, without repetitions (the order of printed values is irrelevant).
For example for arrays



 int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
int[] brr = 2,3,6,8,1,5 ;



the result could be :
7 4 9




It can be used only java.lang. package. It can't be created any arrays, collections or Strings.










share|improve this question
























  • This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

    – RahlSK
    Mar 25 at 12:38






  • 3





    What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

    – jwismar
    Mar 25 at 12:38











  • You can do it by iterating through arr and brr

    – MjM
    Mar 25 at 12:41












  • Yep, definitely, numbers that are defined in array 1, but not in array 2

    – Mark Ladyshev
    Mar 25 at 12:49











  • No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

    – Mark Ladyshev
    Mar 25 at 12:52













-1












-1








-1








I need to write a program which defines two arrays of ints and prints all elements of the first array which do not appear in the second, but each value once only, without repetitions (the order of printed values is irrelevant).
For example for arrays



 int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
int[] brr = 2,3,6,8,1,5 ;



the result could be :
7 4 9




It can be used only java.lang. package. It can't be created any arrays, collections or Strings.










share|improve this question
















I need to write a program which defines two arrays of ints and prints all elements of the first array which do not appear in the second, but each value once only, without repetitions (the order of printed values is irrelevant).
For example for arrays



 int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
int[] brr = 2,3,6,8,1,5 ;



the result could be :
7 4 9




It can be used only java.lang. package. It can't be created any arrays, collections or Strings.







java arrays int






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 13:41







Mark Ladyshev

















asked Mar 25 at 12:35









Mark LadyshevMark Ladyshev

11 bronze badge




11 bronze badge












  • This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

    – RahlSK
    Mar 25 at 12:38






  • 3





    What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

    – jwismar
    Mar 25 at 12:38











  • You can do it by iterating through arr and brr

    – MjM
    Mar 25 at 12:41












  • Yep, definitely, numbers that are defined in array 1, but not in array 2

    – Mark Ladyshev
    Mar 25 at 12:49











  • No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

    – Mark Ladyshev
    Mar 25 at 12:52

















  • This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

    – RahlSK
    Mar 25 at 12:38






  • 3





    What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

    – jwismar
    Mar 25 at 12:38











  • You can do it by iterating through arr and brr

    – MjM
    Mar 25 at 12:41












  • Yep, definitely, numbers that are defined in array 1, but not in array 2

    – Mark Ladyshev
    Mar 25 at 12:49











  • No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

    – Mark Ladyshev
    Mar 25 at 12:52
















This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

– RahlSK
Mar 25 at 12:38





This question is so confusing. Do you mean, numbers defined in array 1 ,but not in array 2 ?

– RahlSK
Mar 25 at 12:38




3




3





What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

– jwismar
Mar 25 at 12:38





What have you tried? (BTW, given the crazy requirements, this sounds like a homework assignment, and we're not really in the business of doing folks' homework for them. We like to help with specific programming problems.) Take a look at stackoverflow.com/help/how-to-ask

– jwismar
Mar 25 at 12:38













You can do it by iterating through arr and brr

– MjM
Mar 25 at 12:41






You can do it by iterating through arr and brr

– MjM
Mar 25 at 12:41














Yep, definitely, numbers that are defined in array 1, but not in array 2

– Mark Ladyshev
Mar 25 at 12:49





Yep, definitely, numbers that are defined in array 1, but not in array 2

– Mark Ladyshev
Mar 25 at 12:49













No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

– Mark Ladyshev
Mar 25 at 12:52





No, it's not HW. This task was on the test, but unfortunately I haven't done this. So now I would like to pass this task just for myself. This is why I'm asking.

– Mark Ladyshev
Mar 25 at 12:52












5 Answers
5






active

oldest

votes


















1














This prints all elements of the first array which do not appear in the second, now you just have to check for repetitions.



 public static void compareArrays(int[] arr1, int[] arr2) 

boolean equal = false;
int[] printed = null;

for (int i = 0; i < arr1.length; i++)
for (int x = 0; x < arr2.length; x++)
if (arr1[i] == arr2[x])
equal = true;
break;
else
equal = false;


if (equal != true)

System.out.println(arr1[i]);




public static void main(String[] args)
int[] arr = 4, 3, 4, 3, 6, 7, 4, 8, 2, 9;
int[] brr = 2, 3, 6, 8, 1, 5;

compareArrays(arr, brr);






share|improve this answer






























    0














    I will give you some pointers, but will not provide any code as I've not seen any attempt from your side. You can tackle this problem several ways, have a look and try to implement this yourself. You will learn much more during the process, rather than if someone gives you a complete full-code answer. So here goes:



    First method:



    1. Create a new ArrayList that will hold your output.

    2. Iterate through the first array, iterate through the second array. Compare each value.

    3. If value is not present and is not present in the output list (you would need to check for that specifically, so you dont have repetition of values), then add it to output list.

    4. Print output list.

    Second method:



    1. Convert both arrays into an ArrayList.


    2. Use the removeAll() method provided with Lists to get difference between the arrays. This will be stored in one of the lists you created earlier.


    3. Remove repetitive items from the list (e.g. using Streams).


    Third method:



    1. Create a new ArrayList that will hold your output.


    2. Iterate through values of array1.


    3. Initialize a boolean variable (e.g. call it contains) that will determine whether a value from array1 is present in array2 using an IntStream.


    4. Create if statement - if contains is true, add the value to your output list. Check that your output List already doesn't have the value and only add if it doesn't. Print output list.






    share|improve this answer
































      0














      Something like this:



      String[] unique = new HashSet<String>(Arrays.asList(arr)).toArray(new String[0]);

      for (int uEach : unique)
      for (int bEach : brr)
      if (unique[uEach] == brr[bEach])
      ArrayUtils.removeElement(unique, uEach);


      ;

      System.out.print(unique);





      share|improve this answer






























        -1














         static void findMissing(int a[], int b[]) 

        for (int i = 0; i < a.length; i++)

        int j;

        for (j = 0; j < b.length; j++)
        if (a[i] == b[j])
        break;

        if (j == b.length)
        System.out.print(a[i] + " ");







        share|improve this answer























        • This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

          – user10778951
          Mar 26 at 4:28


















        -1














        You can use to get distanct value from an array



        int[] unique = Arrays.stream(arr).distinct().toArray(); 


        then loop over both arrays and match strings if not found print that



         int i,j,occ;
        int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
        int[] brr = 2,3,6,8,1,5 ;
        arr = Arrays.stream(arr).distinct().toArray();
        for( i =0; i < arr .length; i++)
        occ = 0;
        for( j =0; j < brr.length; j++)
        if(arr [i] == brr[j])
        occ ++;


        if(occ==0)
        System.out.println(arr [i]);







        share|improve this answer

























        • why a downvote?

          – Syed Mehtab Hassan
          Mar 25 at 13:13











        • I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

          – vs97
          Mar 25 at 13:40











        • It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

          – Mark Ladyshev
          Mar 25 at 13:43












        • @MarkLadyshev that'snot a big problem you can replace the new array with the old one

          – Syed Mehtab Hassan
          Mar 25 at 15:45











        • @MarkLadyshev updated my answer

          – Syed Mehtab Hassan
          Mar 25 at 15:45













        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337920%2fhow-to-output-same-numbers-from-previously-defined-two-different-integer-arrays%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        This prints all elements of the first array which do not appear in the second, now you just have to check for repetitions.



         public static void compareArrays(int[] arr1, int[] arr2) 

        boolean equal = false;
        int[] printed = null;

        for (int i = 0; i < arr1.length; i++)
        for (int x = 0; x < arr2.length; x++)
        if (arr1[i] == arr2[x])
        equal = true;
        break;
        else
        equal = false;


        if (equal != true)

        System.out.println(arr1[i]);




        public static void main(String[] args)
        int[] arr = 4, 3, 4, 3, 6, 7, 4, 8, 2, 9;
        int[] brr = 2, 3, 6, 8, 1, 5;

        compareArrays(arr, brr);






        share|improve this answer



























          1














          This prints all elements of the first array which do not appear in the second, now you just have to check for repetitions.



           public static void compareArrays(int[] arr1, int[] arr2) 

          boolean equal = false;
          int[] printed = null;

          for (int i = 0; i < arr1.length; i++)
          for (int x = 0; x < arr2.length; x++)
          if (arr1[i] == arr2[x])
          equal = true;
          break;
          else
          equal = false;


          if (equal != true)

          System.out.println(arr1[i]);




          public static void main(String[] args)
          int[] arr = 4, 3, 4, 3, 6, 7, 4, 8, 2, 9;
          int[] brr = 2, 3, 6, 8, 1, 5;

          compareArrays(arr, brr);






          share|improve this answer

























            1












            1








            1







            This prints all elements of the first array which do not appear in the second, now you just have to check for repetitions.



             public static void compareArrays(int[] arr1, int[] arr2) 

            boolean equal = false;
            int[] printed = null;

            for (int i = 0; i < arr1.length; i++)
            for (int x = 0; x < arr2.length; x++)
            if (arr1[i] == arr2[x])
            equal = true;
            break;
            else
            equal = false;


            if (equal != true)

            System.out.println(arr1[i]);




            public static void main(String[] args)
            int[] arr = 4, 3, 4, 3, 6, 7, 4, 8, 2, 9;
            int[] brr = 2, 3, 6, 8, 1, 5;

            compareArrays(arr, brr);






            share|improve this answer













            This prints all elements of the first array which do not appear in the second, now you just have to check for repetitions.



             public static void compareArrays(int[] arr1, int[] arr2) 

            boolean equal = false;
            int[] printed = null;

            for (int i = 0; i < arr1.length; i++)
            for (int x = 0; x < arr2.length; x++)
            if (arr1[i] == arr2[x])
            equal = true;
            break;
            else
            equal = false;


            if (equal != true)

            System.out.println(arr1[i]);




            public static void main(String[] args)
            int[] arr = 4, 3, 4, 3, 6, 7, 4, 8, 2, 9;
            int[] brr = 2, 3, 6, 8, 1, 5;

            compareArrays(arr, brr);







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 13:24









            YamsYams

            113 bronze badges




            113 bronze badges























                0














                I will give you some pointers, but will not provide any code as I've not seen any attempt from your side. You can tackle this problem several ways, have a look and try to implement this yourself. You will learn much more during the process, rather than if someone gives you a complete full-code answer. So here goes:



                First method:



                1. Create a new ArrayList that will hold your output.

                2. Iterate through the first array, iterate through the second array. Compare each value.

                3. If value is not present and is not present in the output list (you would need to check for that specifically, so you dont have repetition of values), then add it to output list.

                4. Print output list.

                Second method:



                1. Convert both arrays into an ArrayList.


                2. Use the removeAll() method provided with Lists to get difference between the arrays. This will be stored in one of the lists you created earlier.


                3. Remove repetitive items from the list (e.g. using Streams).


                Third method:



                1. Create a new ArrayList that will hold your output.


                2. Iterate through values of array1.


                3. Initialize a boolean variable (e.g. call it contains) that will determine whether a value from array1 is present in array2 using an IntStream.


                4. Create if statement - if contains is true, add the value to your output list. Check that your output List already doesn't have the value and only add if it doesn't. Print output list.






                share|improve this answer





























                  0














                  I will give you some pointers, but will not provide any code as I've not seen any attempt from your side. You can tackle this problem several ways, have a look and try to implement this yourself. You will learn much more during the process, rather than if someone gives you a complete full-code answer. So here goes:



                  First method:



                  1. Create a new ArrayList that will hold your output.

                  2. Iterate through the first array, iterate through the second array. Compare each value.

                  3. If value is not present and is not present in the output list (you would need to check for that specifically, so you dont have repetition of values), then add it to output list.

                  4. Print output list.

                  Second method:



                  1. Convert both arrays into an ArrayList.


                  2. Use the removeAll() method provided with Lists to get difference between the arrays. This will be stored in one of the lists you created earlier.


                  3. Remove repetitive items from the list (e.g. using Streams).


                  Third method:



                  1. Create a new ArrayList that will hold your output.


                  2. Iterate through values of array1.


                  3. Initialize a boolean variable (e.g. call it contains) that will determine whether a value from array1 is present in array2 using an IntStream.


                  4. Create if statement - if contains is true, add the value to your output list. Check that your output List already doesn't have the value and only add if it doesn't. Print output list.






                  share|improve this answer



























                    0












                    0








                    0







                    I will give you some pointers, but will not provide any code as I've not seen any attempt from your side. You can tackle this problem several ways, have a look and try to implement this yourself. You will learn much more during the process, rather than if someone gives you a complete full-code answer. So here goes:



                    First method:



                    1. Create a new ArrayList that will hold your output.

                    2. Iterate through the first array, iterate through the second array. Compare each value.

                    3. If value is not present and is not present in the output list (you would need to check for that specifically, so you dont have repetition of values), then add it to output list.

                    4. Print output list.

                    Second method:



                    1. Convert both arrays into an ArrayList.


                    2. Use the removeAll() method provided with Lists to get difference between the arrays. This will be stored in one of the lists you created earlier.


                    3. Remove repetitive items from the list (e.g. using Streams).


                    Third method:



                    1. Create a new ArrayList that will hold your output.


                    2. Iterate through values of array1.


                    3. Initialize a boolean variable (e.g. call it contains) that will determine whether a value from array1 is present in array2 using an IntStream.


                    4. Create if statement - if contains is true, add the value to your output list. Check that your output List already doesn't have the value and only add if it doesn't. Print output list.






                    share|improve this answer















                    I will give you some pointers, but will not provide any code as I've not seen any attempt from your side. You can tackle this problem several ways, have a look and try to implement this yourself. You will learn much more during the process, rather than if someone gives you a complete full-code answer. So here goes:



                    First method:



                    1. Create a new ArrayList that will hold your output.

                    2. Iterate through the first array, iterate through the second array. Compare each value.

                    3. If value is not present and is not present in the output list (you would need to check for that specifically, so you dont have repetition of values), then add it to output list.

                    4. Print output list.

                    Second method:



                    1. Convert both arrays into an ArrayList.


                    2. Use the removeAll() method provided with Lists to get difference between the arrays. This will be stored in one of the lists you created earlier.


                    3. Remove repetitive items from the list (e.g. using Streams).


                    Third method:



                    1. Create a new ArrayList that will hold your output.


                    2. Iterate through values of array1.


                    3. Initialize a boolean variable (e.g. call it contains) that will determine whether a value from array1 is present in array2 using an IntStream.


                    4. Create if statement - if contains is true, add the value to your output list. Check that your output List already doesn't have the value and only add if it doesn't. Print output list.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 25 at 13:51

























                    answered Mar 25 at 13:31









                    vs97vs97

                    1,3251 gold badge13 silver badges24 bronze badges




                    1,3251 gold badge13 silver badges24 bronze badges





















                        0














                        Something like this:



                        String[] unique = new HashSet<String>(Arrays.asList(arr)).toArray(new String[0]);

                        for (int uEach : unique)
                        for (int bEach : brr)
                        if (unique[uEach] == brr[bEach])
                        ArrayUtils.removeElement(unique, uEach);


                        ;

                        System.out.print(unique);





                        share|improve this answer



























                          0














                          Something like this:



                          String[] unique = new HashSet<String>(Arrays.asList(arr)).toArray(new String[0]);

                          for (int uEach : unique)
                          for (int bEach : brr)
                          if (unique[uEach] == brr[bEach])
                          ArrayUtils.removeElement(unique, uEach);


                          ;

                          System.out.print(unique);





                          share|improve this answer

























                            0












                            0








                            0







                            Something like this:



                            String[] unique = new HashSet<String>(Arrays.asList(arr)).toArray(new String[0]);

                            for (int uEach : unique)
                            for (int bEach : brr)
                            if (unique[uEach] == brr[bEach])
                            ArrayUtils.removeElement(unique, uEach);


                            ;

                            System.out.print(unique);





                            share|improve this answer













                            Something like this:



                            String[] unique = new HashSet<String>(Arrays.asList(arr)).toArray(new String[0]);

                            for (int uEach : unique)
                            for (int bEach : brr)
                            if (unique[uEach] == brr[bEach])
                            ArrayUtils.removeElement(unique, uEach);


                            ;

                            System.out.print(unique);






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 25 at 14:07









                            anonymousanonymous

                            182 bronze badges




                            182 bronze badges





















                                -1














                                 static void findMissing(int a[], int b[]) 

                                for (int i = 0; i < a.length; i++)

                                int j;

                                for (j = 0; j < b.length; j++)
                                if (a[i] == b[j])
                                break;

                                if (j == b.length)
                                System.out.print(a[i] + " ");







                                share|improve this answer























                                • This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                  – user10778951
                                  Mar 26 at 4:28















                                -1














                                 static void findMissing(int a[], int b[]) 

                                for (int i = 0; i < a.length; i++)

                                int j;

                                for (j = 0; j < b.length; j++)
                                if (a[i] == b[j])
                                break;

                                if (j == b.length)
                                System.out.print(a[i] + " ");







                                share|improve this answer























                                • This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                  – user10778951
                                  Mar 26 at 4:28













                                -1












                                -1








                                -1







                                 static void findMissing(int a[], int b[]) 

                                for (int i = 0; i < a.length; i++)

                                int j;

                                for (j = 0; j < b.length; j++)
                                if (a[i] == b[j])
                                break;

                                if (j == b.length)
                                System.out.print(a[i] + " ");







                                share|improve this answer













                                 static void findMissing(int a[], int b[]) 

                                for (int i = 0; i < a.length; i++)

                                int j;

                                for (j = 0; j < b.length; j++)
                                if (a[i] == b[j])
                                break;

                                if (j == b.length)
                                System.out.print(a[i] + " ");








                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 25 at 13:11









                                user10778951user10778951

                                15 bronze badges




                                15 bronze badges












                                • This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                  – user10778951
                                  Mar 26 at 4:28

















                                • This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                  – user10778951
                                  Mar 26 at 4:28
















                                This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                – user10778951
                                Mar 26 at 4:28





                                This method gives you the numbers which are not in another array yeah, but it will have repetative numbers.But I dont understand why down vote?

                                – user10778951
                                Mar 26 at 4:28











                                -1














                                You can use to get distanct value from an array



                                int[] unique = Arrays.stream(arr).distinct().toArray(); 


                                then loop over both arrays and match strings if not found print that



                                 int i,j,occ;
                                int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
                                int[] brr = 2,3,6,8,1,5 ;
                                arr = Arrays.stream(arr).distinct().toArray();
                                for( i =0; i < arr .length; i++)
                                occ = 0;
                                for( j =0; j < brr.length; j++)
                                if(arr [i] == brr[j])
                                occ ++;


                                if(occ==0)
                                System.out.println(arr [i]);







                                share|improve this answer

























                                • why a downvote?

                                  – Syed Mehtab Hassan
                                  Mar 25 at 13:13











                                • I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                  – vs97
                                  Mar 25 at 13:40











                                • It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                  – Mark Ladyshev
                                  Mar 25 at 13:43












                                • @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45











                                • @MarkLadyshev updated my answer

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45















                                -1














                                You can use to get distanct value from an array



                                int[] unique = Arrays.stream(arr).distinct().toArray(); 


                                then loop over both arrays and match strings if not found print that



                                 int i,j,occ;
                                int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
                                int[] brr = 2,3,6,8,1,5 ;
                                arr = Arrays.stream(arr).distinct().toArray();
                                for( i =0; i < arr .length; i++)
                                occ = 0;
                                for( j =0; j < brr.length; j++)
                                if(arr [i] == brr[j])
                                occ ++;


                                if(occ==0)
                                System.out.println(arr [i]);







                                share|improve this answer

























                                • why a downvote?

                                  – Syed Mehtab Hassan
                                  Mar 25 at 13:13











                                • I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                  – vs97
                                  Mar 25 at 13:40











                                • It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                  – Mark Ladyshev
                                  Mar 25 at 13:43












                                • @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45











                                • @MarkLadyshev updated my answer

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45













                                -1












                                -1








                                -1







                                You can use to get distanct value from an array



                                int[] unique = Arrays.stream(arr).distinct().toArray(); 


                                then loop over both arrays and match strings if not found print that



                                 int i,j,occ;
                                int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
                                int[] brr = 2,3,6,8,1,5 ;
                                arr = Arrays.stream(arr).distinct().toArray();
                                for( i =0; i < arr .length; i++)
                                occ = 0;
                                for( j =0; j < brr.length; j++)
                                if(arr [i] == brr[j])
                                occ ++;


                                if(occ==0)
                                System.out.println(arr [i]);







                                share|improve this answer















                                You can use to get distanct value from an array



                                int[] unique = Arrays.stream(arr).distinct().toArray(); 


                                then loop over both arrays and match strings if not found print that



                                 int i,j,occ;
                                int[] arr = 4,3,4,3,6,7,4,8,2,9 ;
                                int[] brr = 2,3,6,8,1,5 ;
                                arr = Arrays.stream(arr).distinct().toArray();
                                for( i =0; i < arr .length; i++)
                                occ = 0;
                                for( j =0; j < brr.length; j++)
                                if(arr [i] == brr[j])
                                occ ++;


                                if(occ==0)
                                System.out.println(arr [i]);








                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Mar 25 at 15:45

























                                answered Mar 25 at 13:09









                                Syed Mehtab HassanSyed Mehtab Hassan

                                9651 gold badge3 silver badges19 bronze badges




                                9651 gold badge3 silver badges19 bronze badges












                                • why a downvote?

                                  – Syed Mehtab Hassan
                                  Mar 25 at 13:13











                                • I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                  – vs97
                                  Mar 25 at 13:40











                                • It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                  – Mark Ladyshev
                                  Mar 25 at 13:43












                                • @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45











                                • @MarkLadyshev updated my answer

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45

















                                • why a downvote?

                                  – Syed Mehtab Hassan
                                  Mar 25 at 13:13











                                • I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                  – vs97
                                  Mar 25 at 13:40











                                • It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                  – Mark Ladyshev
                                  Mar 25 at 13:43












                                • @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45











                                • @MarkLadyshev updated my answer

                                  – Syed Mehtab Hassan
                                  Mar 25 at 15:45
















                                why a downvote?

                                – Syed Mehtab Hassan
                                Mar 25 at 13:13





                                why a downvote?

                                – Syed Mehtab Hassan
                                Mar 25 at 13:13













                                I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                – vs97
                                Mar 25 at 13:40





                                I didn't downvote you, but I imagine it could be because its not encouraged in SO to give a full code answer to a question that doesn't show an attempt. You answering like this encourages people simply pasting their HW and expecting others to do it for them.

                                – vs97
                                Mar 25 at 13:40













                                It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                – Mark Ladyshev
                                Mar 25 at 13:43






                                It is not HW, it is exercise from the past test, that I haven't done unfortunately. I had a problem with repetitions. And there is used another array, but this should work without any additional arrays.

                                – Mark Ladyshev
                                Mar 25 at 13:43














                                @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                – Syed Mehtab Hassan
                                Mar 25 at 15:45





                                @MarkLadyshev that'snot a big problem you can replace the new array with the old one

                                – Syed Mehtab Hassan
                                Mar 25 at 15:45













                                @MarkLadyshev updated my answer

                                – Syed Mehtab Hassan
                                Mar 25 at 15:45





                                @MarkLadyshev updated my answer

                                – Syed Mehtab Hassan
                                Mar 25 at 15:45

















                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337920%2fhow-to-output-same-numbers-from-previously-defined-two-different-integer-arrays%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현