I am having trouble with my following code in which I have to write a program that allows the user to request a Lucas number (similar to Fibonacci sequence) and then my program is supposed to output that requested Lucas number & the calculated Lucas number.
**However, my problem is that my program is only outputting the requested # and instead of calculating the Lucas number, the Lucas number is always 0!! So, I'm figuring that I have an error in my Lucas code. If someone has any suggestions......I've been working on this code for days & I'm sure it's a simple mistake?!
*I have to write one static method in addition to main
*Use loops to solve the Lucas number series
*Use the double data type to process large Lucas numbers.
----I think I have most of that, however it will not calculate the Lucas number correctly for some reason?? PPPppplease help!!
System.out.printf ("Lucas #%d is %s\n", num, getLucas);
The program doesn't look complete. Does it compile at all?
The above print statement isn't consistent with how getLucas is defined. GetLucas is expected to return a String (%s) but it's defined to return an int. And it isn't called with any parameters at all although it's defined to be passed a double.
Last edited by nuzzle; June 21st, 2011 at 03:08 AM.
Compiling & running are two separate things. You compile the .java source code, which creates a .class file. This .class file is what you run. If compilation failed (which it does when you have syntax errors), then no .class file would have been created so you wouldn't have been able to run anything. (EDIT: be careful though, a previous .class file may still exist).
Even if you are able to successfully compile, it doesn't guarantee that the program is correct. It just means that there were no syntax errors. But there could still be logic errors that cause the program to run, but not behave the way you want it to,.