+ 1

Write a java program to print fibonacci series i.e..,0 1 1 2 3 5 8 13....... with constraints

Write a class FiboanacciSeries with main(String[] args) method for ex: if an int value of 5 is passed then output should be 0 1 1 2 3 5 ex 2: if an int value of 10 is passed then output should be 0 1 1 2 3 5 8 only up to 10 must not exceed 10

25th Aug 2018, 4:47 PM
Sai Chandh Pasupuleti
Sai Chandh Pasupuleti - avatar
7 odpowiedzi
+ 6
Please show your attempts first.
25th Aug 2018, 4:51 PM
Harsh
Harsh - avatar
+ 5
while(a + b < k) works I think
25th Aug 2018, 8:24 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
public class FibonacciSeries { public static void main(String [] args) { int n = Integer.parseInt(args[0]); int a = 1,b = 1,k = 0; System.out.print("0 1 1 "); while(k < n) { k = a + b; System.out.print(k +" "); a = b; b = k; } } } output : FibanacciSeries 10 0 1 1 2 3 5 8 13 guys that is the actual output but 13 must not print only up to 8 it must be printed can any one modify the code for my requirment.
25th Aug 2018, 5:01 PM
Sai Chandh Pasupuleti
Sai Chandh Pasupuleti - avatar
+ 1
if you know please write the code that's my query
25th Aug 2018, 4:49 PM
Sai Chandh Pasupuleti
Sai Chandh Pasupuleti - avatar
0
Where is your code ?
25th Aug 2018, 4:48 PM
KrOW
KrOW - avatar
0
No assignement made from others
25th Aug 2018, 4:52 PM
KrOW
KrOW - avatar
0
public class Program { public static void main(String[] args) { int a=0,b=1,sum=0; do{ System .out .println (sum); a=b; b=sum; sum=a+b; }while(sum<10); } }
25th Aug 2018, 5:04 PM
CHETHAN H.N
CHETHAN H.N - avatar