Advertisement
borsha06

java1

Apr 24th, 2021
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  
  2. import java.util.Arrays;
  3.  
  4. public class Fibonacci {
  5.  
  6.     // implement here
  7.    
  8.     static boolean check(int i,int j,int n)
  9.     {
  10.         if(n<1 || i<j){
  11.            
  12.             return false;
  13.         }
  14.         else {
  15.             return true;
  16.         }
  17.     }
  18.     static int[] fiboSum(int i, int j, int n)
  19.     {
  20.        
  21.         if(check(i,j,n))
  22.        
  23.         {
  24.         int[] arr = new int[10];
  25.         arr[0] = i;
  26.         arr[1] = j;
  27.  
  28.         for (int k = 2; k < n; k++) {
  29.             arr[k] = arr[k - 1] + arr[k - 2];
  30.         }
  31.         return arr;
  32.            
  33.         }
  34.      
  35.        
  36.    
  37.     }
  38.         public static void main(String args[])
  39.     {
  40.         Arrays.toString(Fibonacci.fiboSum(2, 4, 6))
  41.         if(check){
  42.            System.out.println(Arrays.toString(Fibonacci.fiboSum(2, 4, 6)));
  43.         }
  44.           else{
  45.            return System.out.println("Incorrect input data: "+i+" ,"+j+" ,"+ n);
  46.         }
  47.              
  48.            
  49.        
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement