Advertisement
eranseg

Kotlin exercise

Jun 21st, 2020
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.11 KB | None | 0 0
  1. package com.example.myfirstkotlin
  2.  
  3. class MyClass {
  4.  
  5.     fun main(args: Array<String>) {
  6.         print("Hello world")
  7.     }
  8.  
  9.     fun valuesPrinter(vararg values: Int) {
  10.         var greatest: Int = values.get(0)
  11.         var smallest: Int = values.get(0)
  12.         var avg: Int = 0
  13.         var numOfFailures: Int = 0
  14.         values.forEach {
  15. //            if (it < 55) {
  16. //                numOfFailures += 1
  17. //            }
  18.             avg += it
  19.             if (it > greatest) greatest = it
  20.             if (it < smallest) smallest = it
  21.         }
  22.         avg /= values.size
  23.         numOfFailures = values.filter { it < 55 }.size
  24.         println("Average is: $avg")
  25.         println("Greatest is: $greatest")
  26.         println("Smallest is: $smallest")
  27.         println("Number of failures is: $numOfFailures")
  28.     }
  29.  
  30.     fun rectangleData(x: Double, y: Double) {
  31.         val area = x * y
  32.         val perim = 2 * (x + y)
  33.         val diag = Math.sqrt(Math.pow(x, 2.0) + Math.pow(y, 2.0))
  34.         println("Area is: $area")
  35.         println("Perimeter is: $perim")
  36.         println("Diagonal is: $diag")
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement