In: Computer Science
Write code that will produce the following pyramid for a user designated number of rows (user input).
1
11
121
12321
1235321
(Based on Fibonacci numbers)
*USE JAVA*
import java.util.*;
import java.lang.*;
public class Sample{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int n;
n=input.nextInt();
int[] arr=new int[n];
int a=0,b=1;
for(int i=0;i<n;i++){
int c=a+b;
arr[i]=c;
a=b;
b=c;
}
for(int i=1;i<=n;i++){
if(i==1){
System.out.print(1);
}else{
a=0;b=1;
for(int j=1;j<=Math.ceil((float)arr[i-1]/2);j++){
int c=a+b;
System.out.print(c);
a=b;
b=c;
}
a=0;b=1;
for(int j=1;j<=Math.floor((float)arr[i-1]/2);j++){
int c=a+b;
System.out.print(c);
a=b;
b=c;
}
}
System.out.println("");
}
}
}