package deret;
public class fibonacci {
public static void main(String args[])
{
int elemen = 1;
int a = 1;
int b = 1;
int max_length = 50;
int limit = 500;
int[] fib = new int[max_length]; // membuat array
fib[0] = a;
//proses hasil inputan pertama yaitu a
while(a <= limit)
{
a = a + b;
b = a - b;
if (a <= limit)
{
fib[elemen] = a;
elemen++;
}
}
System.out.println();
//menampilkan hasil array
for(int i=0;i< elemen;i++)
{
System.out.print(fib[i] + " ");
}
}
}
thanks gan sudah share
BalasHapustimah solder