I'm working with metrowerks codewarrior to do this program.

This program asks you to create fibonacci sums up to 2^23 and then asks you to do some more stuff after that.

I'm just wondering if you would set up an array or a for or a while loop to complete this program easier and how would you set that up?

Since fibonacci is the last 2 added together to create the next integer i was thinking along the lines of a + b = sum and then save it to part of an array. Then create an if statement after to make it so that when the next integer is bigger than b then it replaces b and the old b replaces a.

Am i thinking along the right lines??

except of course an array would be useless since you wouldn't know the size of the array behorehand.
You'll have to use some ordered Collection to store your results.

:) hi:
you can see that code.Maybe is right.

package com.jmenu;
public class Fibonacci {
public static void main(String agre[]){
double frontsum=0;
int finditem=3;
double a=Double.parseDouble(agre[0]);
System.out.println(a);
frontsum = calculateItemSum(finditem);
do{
finditem++;
frontsum+=calculateItemSum(finditem);
}while(frontsum<a);
System.out.printf("sum is: %f",frontsum);
System.out.printf("item is: %d",finditem);
System.out.printf("\nitem is: %f",calculateItemSum(96));
System.out.printf("\n -: %f",frontsum-calculateItemSum(96));
}
 
 
 
static double calculateItemSum(int i){
double a=2,b=2,c=0;
int item=3;
while(item<=i){
c=a+b;
a=b;
b=c;
item++;
}
return c;
}
}
This article has been dead for over six months. Start a new discussion instead.