|
-
May 6th, 2006, 06:37 PM
#1
Thread Starter
New Member
trouble with Fibonacci
Hi, I'm pretty new to java and right now, I feel like one of those aliens from Mars Attacks whos' heads explode when listening to country music. This "simple" program I am supposed to write is gnawing at my soul and I want to say it is impossible to do, but I think I just need a little guidance.
I am supposed to write a program that asks the user to pick the Fibonacci number he wants, and the program prints out that value. If the user puts in a negative value, the program should print out an error message and ask for another number.
This is what I have thus far.
What should I do...or what am I doing wrong? Thanks
import java.util.Scanner;
class Fibtry {
public static void main (String[] args) {
Scanner input=new Scanner (System.in);
long var1 = 0;
long var2 = 1;
System.out.println("Compute which Fibonacci number: ");
var1=input.nextInt();
{
long var3 = var1;
var1 += var2;
var2 = var3;
System.out.println("Fibonacci number is equal to " + var1);
}
}
}
Last edited by BALLOONforME; May 6th, 2006 at 07:41 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|