Advertisement
fannyxmikasa

Untitled

Oct 20th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.48 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.     do
  6.     {   print("Enter a valid value for n: ") //n of sequence
  7.         val reader = Scanner(System.`in`)
  8.         val n:Int = reader.nextInt()
  9.         maxSeq = n
  10.     }while(n <= 0)
  11.  
  12.     do
  13.     {   nTerm = n1 + n2
  14.         println(nTerm)
  15.         //update value of n1 and n2
  16.         n1 = n2
  17.         n2 = nTerm
  18.         maxSeq--
  19.     }while(maxSeq > 0)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement