Please HELP me URGENT - Programmers Heaven

Howdy, Stranger!

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

Categories

Please HELP me URGENT

shoyeb4meshoyeb4me 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.

Comments

  • zibadianzibadian 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.
  • shoyeb4meshoyeb4me 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.
  • zibadianzibadian 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.
Sign In or Register to comment.