Please modify my code fibonacci series | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Please modify my code fibonacci series

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:03 PM
Sai Chandh Pasupuleti
Sai Chandh Pasupuleti - avatar
1 Answer
0
may be you should add an if statement to your code that test that k is less than args[0]: if(k<args[0]) break;
25th Aug 2018, 5:23 PM
Ramzi Zelfani
Ramzi Zelfani - avatar