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 7 of 7

Thread: Java Logic

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Java Logic

    We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return true if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops.

    I'm not sure how this could be done using simple logic and no loops. Please explain


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java Logic

    math is your friend

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Logic

    Thanks i was planning on using words

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Java Logic

    I think the problem given is incomplete

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java Logic

    Quote Originally Posted by hurrah View Post
    I think the problem given is incomplete
    If you read it closely, there is enough information given to solve the problem.

  6. #6
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Logic

    Quote Originally Posted by jps View Post
    If you read it closely, there is enough information given to solve the problem.
    ive gotten this far
    public boolean makeBricks(int small, int big, int goal) {
      if ((big & small)> 0){
        if (goal%(big*5)<=small){
          return true;
        }else{
          return false;
        }
      }
      return false;
     
     }
    but still have a few tests that it does not work for what am i missing?
    Last edited by jps; November 7th, 2012 at 04:26 PM. Reason: added code tags

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java Logic

    Please see the announcements page for the use of code tags as well as other useful forum tips.

    but still have a few tests that it does not work for what am i missing?
    Include your test set, and show which values pass and which values failed.
    We will use the test values to troubleshoot the code.

Similar Threads

  1. Java for loops to count vowels/consonants usinf the logic of the main
    By willie lee in forum Loops & Control Statements
    Replies: 41
    Last Post: June 18th, 2012, 04:01 AM
  2. need logic
    By arunjib in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2011, 05:39 PM
  3. Help with java logic
    By dever in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 08:41 AM
  4. Java Dos Logic Test count all non increasing number
    By Jhovarie in forum Object Oriented Programming
    Replies: 3
    Last Post: January 13th, 2011, 03:28 PM
  5. java Logic Random with out repetition
    By Jhovarie in forum Loops & Control Statements
    Replies: 1
    Last Post: January 13th, 2011, 03:25 PM