Question #11050283

What is wrong with my Java program?

I'm a beginner and I'm trying to make a program that will calculate the nth Fibonacci number: int n = ...; if (n < 47) { if (n > 0) { if (n != 1) { System.out.println(1); System.out.println(1); int x = 1; int f1 = 1; int f2 = 1; int fn; while (x < n-1) { fn = f1 + f2; f1 = f2; f2 = fn; x = x + 1; } System.out.println(fn); } else System.out.println(1); } else System.out.println("There is no such thing as the " + n + "th Fibonacci number you idiot!"); Where ... is the nth Fibonacci number (so if I want the 5th Fibonacci number, I replace ... with 5). But my program keeps on getting an error. Why???

2013-10-13 07:16:36

TELL US , if you have any answer

There is NEVER a problem, ONLY a challange!

The helpinganswers.com is a free-to-use knowledgebase.
  The helpinganswers.com was started on: 02.07.2010.
  It's free to register. Once you are a registered user, you can ask questions, or answer them.
  (Unless registration you can just answer the questions anonymously)
  Only english!!! Questions and answers in other languages will be deleted!!

Cheers: the PixelFighters

  Contact: support@helpinganswers.com

C'mon... follow us!

Made by, history, ect.