Advertisement
fannyxmikasa

Untitled

Oct 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.49 KB | None | 0 0
  1. import java.util.Scanner
  2. fun main()
  3. {   /*first term  is 1*/
  4.     var n1 = 0; var n2 = 1; var maxSeq:Int; var nTerm: Int
  5.  
  6.     do
  7.     { print("Enter a valid value for n: ") //n of sequence
  8.         val reader = Scanner(System.`in`)
  9.         val n:Int = reader.nextInt()
  10.         maxSeq = n
  11.     }while(n <= 0) //iterate while n is <= zero
  12.  
  13.     for(i in 1..maxSeq)
  14.     {   nTerm = n1 + n2
  15.         println(nTerm)
  16.         //update value of n1 and n2
  17.         n1 = n2
  18.         n2 = nTerm
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement