Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do I do this:

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How do I do this:

    I want to distribute a certain number of items to an indefinite number of recipients, how do I code it?
    I have this:

    item = getitem.items();
    LinkedList<String>[] distributedItems = new LinkedList<String>[item];
    while (item !=0){
    if (int c=0; c<r; c++){
    recipientNum[].add(item.pollFirst());
    else {
    break;
    }
    }
    return distributedItems;
    }

    where getitem.items is previously process method that I have to call which I assigned to item, r is the number of recipients, recipientNum was determined by this:

    LinkedList<String>[] recipientNum = new LinkedList[r];
    for (int z=0; z<r; z++){
    recipientNum[z] = new LinkedList<String>();
    System.out.println ("recipientNum[" + z + "]");
    }
    return recipientNum;


    I have this error when trying to code:

    while (card !=0){ --> Multiple markers at this line
    - Syntax error on token "isEmpty", delete this token
    - The method card() is undefined for the type Table
    - Incompatible operand types LinkedList<String> and int

    if (int c=0; c<p; c++){ --> Multiple markers at this line
    - Syntax error on token "<", invalid Assignment Operator
    - Syntax error on token ")", ; expected
    - Syntax error on token(s), misplaced construct(s)


    playerNum[].add(card.pollFirst()); --> Syntax error on token "[", Expression expected after this token

    else { --> Syntax error on token "else", delete this token.

    Why do I get these errors? Thank you in advance for your help guys ..

  2. #2
    Member
    Join Date
    Apr 2012
    Posts
    163
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: How do I do this:

    I would recommend you check out a few beginner tutorials as you have many things going wrong all at once. For instance, your if statement:
    if (int c=0; c<r; c++)

    What you are trying to use there would be a for loop. An if statement will only take a boolean value as its parameters. You also didn't close the if statement until after the else statement.