Advertisement
fannyxmikasa

Untitled

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