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

Thread: Some basic for loops I'm stuck on.

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Some basic for loops I'm stuck on.

    Sequences for n = 5:

    1 2 6 12 20

    1 2 6 24 120

    1 4 9 16 25

    100 50 200 100 400

    2 5 8 11 14

    1 3 6 10 15

    1 1 2 3 5 8 13

    0 2 6 12 20

    20 22 18 24 16

    0 1 3 7 15


    I have to make it so it prints that, each on a new line, exactly like that.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Some basic for loops I'm stuck on.

    What do you expect us to do, write the code for you?

    How about working out what the sequence for each output is. Some are easier than others. Once you know the sequence, the Java code will follow.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Some basic for loops I'm stuck on.

    Quote Originally Posted by Junky View Post
    What do you expect us to do, write the code for you?

    How about working out what the sequence for each output is. Some are easier than others. Once you know the sequence, the Java code will follow.
    I'm aware of the sequence for some, not all.
    I'd post the code I have if I was at school at the moment.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Some basic for loops I'm stuck on.

    Each loop will require 2 or more variables. You might also need to ise an if statement inside some of the loops. None are very difficult.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Some basic for loops I'm stuck on.

    Quote Originally Posted by Junky View Post
    Each loop will require 2 or more variables. You might also need to ise an if statement inside some of the loops. None are very difficult.
    That really doesn't help me. I realize what I'm supposed to do, but I can't figure out how to do it.

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Some basic for loops I'm stuck on.

    But if I told you how to do it I would have done the work not you. On the other hand if you make an attempt, get stuck and ask a specific question about your code I can provide hints and guide you towards doing the work yourself.
    Improving the world one idiot at a time!

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

    Default Re: Some basic for loops I'm stuck on.

    Quote Originally Posted by Junky View Post
    But if I told you how to do it I would have done the work not you. On the other hand if you make an attempt, get stuck and ask a specific question about your code I can provide hints and guide you towards doing the work yourself.
    I'd post my code, but unfortunately I'm at school and can't access the necessary files for BlueJ on the school server. Thanks anyways.

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Some basic for loops I'm stuck on.

            a = 1;
            int b = 1;
            for (int i = 1; i <= n; i++) //come back to this later
            {
                System.out.print(a + " ");
     
     
     
     
     
        }

    There's my code. (For the first set of outputs)

  9. #9
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Some basic for loops I'm stuck on.

    Does it compile?
    Does it run?
    Does it do what you want?
    Improving the world one idiot at a time!

Similar Threads

  1. Help! im stuck!
    By aznguy92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2011, 09:16 PM
  2. Java Basic - explanation of for loops
    By dubell in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 24th, 2011, 07:55 PM
  3. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  4. PLEASE PLEASE I AM STUCK...
    By ThejavaBUM in forum Loops & Control Statements
    Replies: 2
    Last Post: April 5th, 2011, 10:16 PM
  5. I'm stuck
    By iank in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2009, 09:21 AM