Question #3478

(1) Write a program to create an array with size of 10 elements and give the ten values to the array and print those values on the console.

Expert's answer

public class Task8
{
public static void main(String[] args)
{
& // The array that contains the first 10 fibonacci numbers
& int[] fibonArray = new int[10];
& fibonArray[0] = fibonArray[1] = 1;
& for (int i = 2; i < 10; i++)
& fibonArray[i] = fibonArray[i - 1] + fibonArray[i - 2];

& // Printing the array to the console
& System.out.print("The array values:\n" + fibonArray[0]);
& for (int i = 1; i < 10; i++)
& System.out.print(", " + fibonArray[i]);
}
}
LATEST TUTORIALS
APPROVED BY CLIENTS