2 Replies - 168 Views - Last Post: 10 January 2013 - 09:26 AM Rate Topic: -----

#1 jwhiteknight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;

System.out.print ("Please input your number: ");
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  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,753
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1