Using arrays write an application that estimates the value o
Solution
public class ComputeE{ //class containing function for fibsequence
int sumE() //function for calculating and printing fibsequence upto 8 numbers
{
int[] fibe=new int[8]; //array for storage
fibe[0]=1; //first number according to the condition must be 1
fibe[1]=1; //second number according to the condition must be 1
int sum=0; //variable for storing sum value
sum=sum+fibe[0]+ fibe[1];
System.out.print(\"E = \"+fibe[0]+\"+\"+fibe[1]+\"+\");
for(int i=2;i<8;i++) //loop upto 8 numbers
{
fibe[i]=fibe[i-2]+fibe[i-1]; // According to the fibsequence each term from second index must be the sum of previous two terms
System.out.print(fibe[i]+\"+\"); //printing the fibsequence
sum=sum+fibe[i];
}
System.out.println(\"\ The sum of the E upto 8 numbers = \"+sum); //printing the final sum of the fibsequence
return 0;
}
} //end of class ComputeE
public class ComputeETest{ //another class containing main method
public static void main(String []args) //main method
{
ComputeE e=new ComputeE(); // creating object of ComputeE class
e.sumE(); //calling sumE method of ComputeE class through object of ComputeE class
}
} //end of class ComputeETest
**********OUTPUT**********
E = 1+1+2+3+5+8+13+21+
The sum of the E upto 8 numbers = 54
**********OUTPUT**********
Note:save the ComputeE class in a file and name it ComputeE.java
save the ComputeETest class in a file and name it ComputeEtest.java
Please let me know in case of any question.
