TheBulgarianWolf

Default and Named Arguments

Mar 23rd, 2021
655
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun displayBorder(character: Char = '=', length: Int = 15) {
  2.     for (i in 1..length) {
  3.         print(character)
  4.     }
  5. }
  6.  
  7. fun main(args: Array<String>) {
  8.     println("Output when no argument is passed:")
  9.     displayBorder()
  10.  
  11.     println("\n\n'*' is used as a first argument.")
  12.     println("Output when first argument is passed:")
  13.     displayBorder('*')
  14.  
  15.     println("\n\n'*' is used as a first argument.")
  16.     println("5 is used as a second argument.")
  17.     println("Output when both arguments are passed:")
  18.     displayBorder('*', 5)
  19.  
  20. }
RAW Paste Data