The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: URGENT HELP NEEDED WITH Iterative statements for loops

  1. #1

    URGENT HELP NEEDED WITH Iterative statements for loops

    i need a program which outputs a series of asterisks (* - stars) to form the following pattern below.

    i think in order to get the second half of the pattern you will need another set of for loops, this time counting down or you can try to change over the loop control and decrement after 5.

    The output should look like: (this is a short version, you should have 10 lines of stars)

    *
    **
    ***
    ****
    *****
    ******
    *****
    ****
    ***
    **
    *


    i then need a METHOD which produces the Fibonacci series when called.

    The series is formed by adding two numbers in the series to generate the third. Note the first two are 0 and 1, so to make the make number we add 0 + 1 to give 1. The fourth number is obtained by adding the second and third numbers, 1 + 1 gives 2. So the series looks like:


    0 1 1 2 3 5 8 13 21


    All help is really appreciated and i may be able to reward any one for their help. Thanks
    Last edited by mayjarboi; March 31st, 2008 at 08:26 PM. Reason: added more requirements

  2. #2
    1,627
    posts
    hugeExplosions = true;
    Which language would you like this program in?

    Is this for school/college/uni whatever?
    MS Paint FTW!


  3. #3
    sorry i wanted it in java please

  4. #4
    doesn't really matter what language it is for, and i'm going to guess it is in college seeing how this is like an introduction type problem.

    yes, you want two loops for the * problem. One to count up, one to count down.

    count = 5

    for (int x = 0; x < count ; x++)
    {
    WriteStars(x);
    }


    for (int x = count; x > 0 ; x--)
    {
    WriteStars(x);
    }


    public void WriteStars(int count)
    {
    for (int x=0; x< count; x++)
    Write('*');
    Write('\n');
    }


    thats in c# or c in general, i'm sure you can figure out hwo to change it over to java.

    for the next problem (i so bored i'm actually answering this)...

    public void Fib(int prev, current)
    {
    int next = prev + current;
    write (next);
    fib(current, next);
    }

    now you didn't say how to really start it off, form main you could call Fib(1,1) or you can make a function called StartFib which just does the Fib(1,1). Also you didn't say how many times to do it, so this will go on forever. If you want it to stop, i would put some sort of break condition like eithre a number cap or a loop cap.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012