#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Posts: 2Member
I am a novish in Java Wolrd. I m trying to learn it. Anyway I am getting one problem while I am trying to solve one

problem. The problem is

[B]First you have create an array A of unsorted random integers and will have to repoduce an array B which contains

all integres from A without repetitions.

For example, given array A = [1,2,5,6,6,3,3,2,9,6,8], the program will produce array B = [1,2,5,6,3,9,8] where no

repetitions are allowed .[/B]

If anybody please help me by providing code I will be very happy and greatful.It will help me to learn.

Thank u all.
· ·

• Posts: 6,349Member
: I am a novish in Java Wolrd. I m trying to learn it. Anyway I am getting one problem while I am trying to solve one
:
: problem. The problem is
:
: [B]First you have create an array A of unsorted random integers and will have to repoduce an array B which contains
:
: all integres from A without repetitions.
:
: For example, given array A = [1,2,5,6,6,3,3,2,9,6,8], the program will produce array B = [1,2,5,6,3,9,8] where no
:
: repetitions are allowed .[/B]
:
:
: If anybody please help me by providing code I will be very happy and greatful.It will help me to learn.
:
: Thank u all.
:
Here's the array definitions.
[code]
int[] a, b;
[/code]
The rest is a simple for() loop to remove the doubles and an if()-statement to check if the value already exists in array b.
Programming can only be learned by doing it, not by reading it.
· ·
• Posts: 2Member
this way i tried before. I did the first part to create a an arry of numbers. I just coudnt finish the operation to remove duplicate integres. If u please provide the code how to remove duplicates and check again, i will be greatful to u.

Thank u.
· ·
• Posts: 6,349Member
: this way i tried before. I did the first part to create a an arry of numbers. I just coudnt finish the operation to remove duplicate integres. If u please provide the code how to remove duplicates and check again, i will be greatful to u.
:
: Thank u.
:
Here's the algorithm in pseudocode:
[code]
for (int i = 0; i < source array length; i++) {
if source[i] in dest array {
copy source[i] to dest array
}
}
[/code]
The main difficulty would be the if-statement. This is easiest using another loop:
[code]
index = -1;
for (int j = 0; j < dest array length; j++) {
if source[i] == dest[j] index = j;
}
[/code]
Now if index equals -1 then source[i] doesn't exist in the dest array.
· ·