Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myfirstkotlin
- class MyClass {
- fun main(args: Array<String>) {
- print("Hello world")
- }
- fun valuesPrinter(vararg values: Int) {
- var greatest: Int = values.get(0)
- var smallest: Int = values.get(0)
- var avg: Int = 0
- var numOfFailures: Int = 0
- values.forEach {
- // if (it < 55) {
- // numOfFailures += 1
- // }
- avg += it
- if (it > greatest) greatest = it
- if (it < smallest) smallest = it
- }
- avg /= values.size
- numOfFailures = values.filter { it < 55 }.size
- println("Average is: $avg")
- println("Greatest is: $greatest")
- println("Smallest is: $smallest")
- println("Number of failures is: $numOfFailures")
- }
- fun rectangleData(x: Double, y: Double) {
- val area = x * y
- val perim = 2 * (x + y)
- val diag = Math.sqrt(Math.pow(x, 2.0) + Math.pow(y, 2.0))
- println("Area is: $area")
- println("Perimeter is: $perim")
- println("Diagonal is: $diag")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement