# fibonacci loop repeadly ask the user a question unless user enter "

Page 1 of 1

## 2 Replies - 252 Views - Last Post: 10 January 2013 - 09:26 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=306532&amp;s=52b5b52a1f96318b26a7d4a341189690&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jwhiteknight

• New D.I.C Head

Reputation: 0
• Posts: 14
• Joined: 09-January 13

# fibonacci loop repeadly ask the user a question unless user enter "

Posted 10 January 2013 - 07:39 AM

I need help creating a loop.The loop will ask the user for a number in the Fibonacci series. if the user enter 3... the program will print out 2, the program will keep asking the user to enter a new number unless the user enters 0
```
```

Scanner i = new Scanner (System.in);

System.out.println("Given a number n, this program will return the N-th Fibonacci number in an interger type.\n");

do
{

int number = 0;

number = i.nextInt();

System.out.printf (" The %d-th is fibinocci number is %.0f\n",number, fibcalic(number));

}
while (number != 0);

}

} // end main method

public static int fibcalic(int number)// method
{
int max = number;
int[] fibarray = new int [max];// set the array to int max is still int

fibarray [0] = 0;
fibarray [1] = 1;

for (int a=2; a < max; a++)
{
fibarray[a] = fibarray[a -1] + fibarray[a -2];
}
return fibarray[number];
}
```
```

Is This A Good Question/Topic? 0

## Replies To: fibonacci loop repeadly ask the user a question unless user enter "

### #2 SpAm101

Reputation: 11
• Posts: 54
• Joined: 28-November 12

## Re: fibonacci loop repeadly ask the user a question unless user enter "

Posted 10 January 2013 - 07:49 AM

Hi jwhiteknight

You program should do what you ask. What is the issue you're having?

### #3 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11387
• Posts: 42,901
• Joined: 27-December 08

## Re: fibonacci loop repeadly ask the user a question unless user enter "

Posted 10 January 2013 - 09:26 AM

Please avoid duplicate posting.