+ 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
7 ответов
+ 6
Please show your attempts first.
+ 5
while(a + b < k) works I think
+ 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.
+ 1
if you know please write the code that's my query
0
Where is your code ?
0
No assignement made from others
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);
        
    
    
}
}



