TheBulgarianWolf

Kotlin_Functions

Mar 18th, 2021
650
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun addNumbers(n1: Double, n2: Double): Int {
  2.     val sum = n1 + n2
  3.     val sumInteger = sum.toInt()
  4.     return sumInteger
  5. }
  6.  
  7. fun callMe() {
  8.     println("Printing from callMe() function.")
  9.     println("This is cool (still printing from inside).")
  10. }
  11.  
  12. class Structure() {
  13.  
  14.     infix fun createPyramid(rows: Int) {
  15.         var k = 0
  16.         for (i in 1..rows) {
  17.             k = 0
  18.             for (space in 1..rows-i) {
  19.                 print("  ")
  20.             }
  21.             while (k != 2*i-1) {
  22.                 print("* ")
  23.                 ++k
  24.             }
  25.             println()
  26.         }
  27.     }
  28. }
  29.  
  30. fun main(args: Array<String>) {
  31.     val number1 = 12.2
  32.     val number2 = 3.4
  33.     val result: Int
  34.     callMe()
  35.     result = addNumbers(number1, number2)
  36.     println("result = $result")
  37.     val p = Structure()
  38.     p createPyramid 4
  39. }
RAW Paste Data