In this assignment, you will write a Java program to print the first 15 Fibonacc
ID: 3851107 • Letter: I
Question
In this assignment, you will write a Java program to print the first 15 Fibonacci numbers. Each number must occupy one line, with even numbers having a * appending to it. You must include your name, class number, instructor name, a pledge in your comment. Indention must be used for any sub-blocks: any sub-block must use 2 space characters more than its parent block.
Here is a sample:
//Name: John Kat
//Time: Sept. 21, 2016
//Class: Programming with UNIX, section 8
//Instructor: John kat /*Pledge: I, john kat, did not receive any help for this programming assignment.*/
//a sample program class …
Submit a copy of your program, the result from running your program before class
Explanation / Answer
public class HelloWorld{
public static void main(String []args){
int numberofelements = 15;
int[]fibon = new int[numberofelements];
fibon[0] = 0;
fibon[1] = 1;
for(int i=2; i < numberofelements; i++){
fibon[i] = fibon[i-1] + fibon[i-2];
}
for(int i=0; i< numberofelements; i++){
System.out.print(fibon[i]);
//To include asterisk for every even number
if(fibon[i] % 2 == 0){
System.out.print('*');
}
System.out.print(' ');
System.out.println();
}
}
}