Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Norm View Post
    The OP said he was NOT allowed to use loops to solve this.
    Ok, fine with me (although I don't understand the reason behind it); simply unroll the loop and use four if-statements like this:

    Java Code:
    if (array[0]) count++;
    if (array[1]) count++;
    if (array[2]) count++;
    if (array[3]) count++;
    ... and test the value of 'count' at the end; trying to combine the truth values in the array results in an if-statements with 16 clauses which I find even sillier than the solution above ;-)

    kind regards,

    Jos

  2. #22
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    Ok, fine with me (although I don't understand the reason behind it);
    Since it is a course, there are probably a few restrictions on what they can and can't do. When I was stuck in a beginner Python course last year, I was allowed to do whatever I wanted on the assignments for the most part ('cause my teacher was nice), but if the assignment said "solve this using the methods used in class thus far," I wasn't able to use anything more advanced.

  3. #23
    hoosierfan24 is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    ok so i finally figured it out thanks sorry if i was a pain i am just not that good at java yet
    here was my final code

    Java Code:
    int count =0;
    if (b[0]) count++;
    if (b[1]) count++;
    if (b[2]) count++;
    if (b[3]) count++;
    if (count > 1)
    onlyone = false;
    else
    onlyone = true;
    Last edited by hoosierfan24; 10-04-2010 at 01:33 AM. Reason: changed my mind

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Did your assignment allow you to use an int as counter?

  5. #25
    hoosierfan24 is offline Member
    Join Date
    Oct 2010
    Posts
    45
    Rep Power
    0

    Default

    yes it did.
    my class is through eimacs.com the ap computer science course if you are familiar with it

Page 2 of 2 FirstFirst 12

Similar Threads

  1. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 11:32 AM
  2. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 02:40 AM
  3. Finding Strings, booleans and Integers
    By Pez in forum SWT / JFace
    Replies: 1
    Last Post: 07-19-2009, 03:24 PM
  4. Help!! With arrays
    By ookie833 in forum New To Java
    Replies: 8
    Last Post: 12-14-2008, 01:57 AM
  5. Arrays
    By TheRocket in forum New To Java
    Replies: 6
    Last Post: 12-10-2008, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •