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;
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
add a comment |
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
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 througharr
andbrr
– 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
add a comment |
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
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
java arrays int
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 througharr
andbrr
– 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
add a comment |
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 througharr
andbrr
– 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
add a comment |
5 Answers
5
active
oldest
votes
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);
add a comment |
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:
- Create a new ArrayList that will hold your output.
- Iterate through the first array, iterate through the second array. Compare each value.
- 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.
- Print output list.
Second method:
Convert both arrays into an ArrayList.
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.
Remove repetitive items from the list (e.g. using Streams).
Third method:
Create a new ArrayList that will hold your output.
Iterate through values of array1.
Initialize a boolean variable (e.g. call it
contains
) that will determine whether a value from array1 is present in array2 using an IntStream.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.
add a comment |
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);
add a comment |
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] + " ");
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
add a comment |
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]);
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 25 at 13:24
YamsYams
113 bronze badges
113 bronze badges
add a comment |
add a comment |
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:
- Create a new ArrayList that will hold your output.
- Iterate through the first array, iterate through the second array. Compare each value.
- 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.
- Print output list.
Second method:
Convert both arrays into an ArrayList.
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.
Remove repetitive items from the list (e.g. using Streams).
Third method:
Create a new ArrayList that will hold your output.
Iterate through values of array1.
Initialize a boolean variable (e.g. call it
contains
) that will determine whether a value from array1 is present in array2 using an IntStream.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.
add a comment |
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:
- Create a new ArrayList that will hold your output.
- Iterate through the first array, iterate through the second array. Compare each value.
- 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.
- Print output list.
Second method:
Convert both arrays into an ArrayList.
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.
Remove repetitive items from the list (e.g. using Streams).
Third method:
Create a new ArrayList that will hold your output.
Iterate through values of array1.
Initialize a boolean variable (e.g. call it
contains
) that will determine whether a value from array1 is present in array2 using an IntStream.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.
add a comment |
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:
- Create a new ArrayList that will hold your output.
- Iterate through the first array, iterate through the second array. Compare each value.
- 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.
- Print output list.
Second method:
Convert both arrays into an ArrayList.
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.
Remove repetitive items from the list (e.g. using Streams).
Third method:
Create a new ArrayList that will hold your output.
Iterate through values of array1.
Initialize a boolean variable (e.g. call it
contains
) that will determine whether a value from array1 is present in array2 using an IntStream.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.
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:
- Create a new ArrayList that will hold your output.
- Iterate through the first array, iterate through the second array. Compare each value.
- 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.
- Print output list.
Second method:
Convert both arrays into an ArrayList.
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.
Remove repetitive items from the list (e.g. using Streams).
Third method:
Create a new ArrayList that will hold your output.
Iterate through values of array1.
Initialize a boolean variable (e.g. call it
contains
) that will determine whether a value from array1 is present in array2 using an IntStream.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.
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
add a comment |
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 25 at 14:07
anonymousanonymous
182 bronze badges
182 bronze badges
add a comment |
add a comment |
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] + " ");
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
add a comment |
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] + " ");
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
add a comment |
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] + " ");
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] + " ");
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
add a comment |
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
add a comment |
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]);
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
add a comment |
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]);
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
add a comment |
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]);
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]);
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
andbrr
– 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