Hi, I have to display the first 20 Fibonacci numbers to the console. The first two numbers are given, 0 and 1. The sequence continues adding the previous two numbers. 0, 1, 1, 2, 3, 5, ... I have to...


Hi, I have to display the first 20 Fibonacci numbers to the console.


The first two numbers are given, 0 and  1. The sequence continues adding the previous two numbers.


0, 1, 1, 2, 3, 5, ...


I have to generate this sequence using a for loop starting with the 3rd number. The first two numbers are given.


The numbers shall be formatted using theprintf statement such that 5 numbers are displayed in a row.


Once all of the numbers are derived and displayed to the console, I have to display the sum and the average of the 20 numbers.



Then I have to generate another sequence of numbers 1, 2, 4, 8, 16, 32, ...


This also requires using a for loop.


Then I have to calculate the sum and the average, and display it to the console.


This is an absolutely imperfect coding. The other half is just me trying something that may work. I'll keep working on it while I wait on a response to see if I'm on the right track.



Here's what I got so far:


import java.util.Scanner

public class PrSpecial {


public static final int N = 20;


public static void main(String[] args) {


 int[] ary = new int[N];


 ary[0]=0;

 ary[1]=1;


 for (int i = 2; i < n;="" i++)="">

  ary[i] = ary[i-1]+ary[i-2];



 }


 for (int i = 0; i < n;="" i++)="">


  System.out.printf("ary[%d] = %3d\n", i, ary[i]);


 }

 {



 Scanner number = new Scanner(System.in);


 int sum = 0;


 System.out.print("Enter sequence")

 for(int i = 1; i

 {

  ary[i]= number.nextInt();

  su

  System.out.print(i+" ");

 }





 }


}


}




This is for java. Please include explanation with the steps so I can understand. I also didn't learn about about the variable of long yet. If you can use a different variable that would be great. Thanks!
Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here