|
-
June 21st, 2011, 07:51 AM
#4
Re: Lucas/Fibonacci sequence HELP please!!
public class Lucas
{
public static void main ( String args [] )
{
System.out.println ("Which Lucas number would you like? ");
Scanner input = new Scanner ( System.in );
double num = input.nextDouble();
while ( num < 0 || num > 76 )
{
System.out.print ("Which Lucas number would you like? ");
num = input.nextInt();
}
System.out.printf ("Lucas #%d is %s\n", num, getLucas);
}
public static int getLucas(double result)
{
double pre = 2;
result = 1;
for ( int i = 0; i <= num; ++i )
{
int sum = result + pre;
pre = result;
result = sum;
}
return result;
}
}
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
|