Answer to Question #3478 in Java | JSP | JSF for Y mukundareddy

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.
1
Expert's answer
2011-08-07T07:17:49-0400
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]);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS