Advertisement
jasurbekdev

Untitled

Sep 16th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.94 KB | None | 0 0
  1.  
  2.  
  3. fun main(args: Array<String>) {
  4.     print("Enter width: ")
  5.     val width = readLine()
  6.     print("Enter height: ")
  7.     val height = readLine()
  8.     print("Enter square side: ")
  9.     val squareSide = readLine()
  10.     val numOfSquares = countFittingSquares(width, height, squareSide)
  11.     println(numOfSquares)
  12. }
  13.  
  14. fun countFittingSquares(width: String?, height: String?, squareSide: String?): Int {
  15.     var widthCount = 0
  16.     var widthEstimate = squareSide?.toInt()!!
  17.     while (widthEstimate <= width?.toInt()!!) {
  18.         widthCount++
  19.         widthEstimate += squareSide?.toInt()!!
  20.     }
  21.     var heightCount = 0
  22.     var heightEstimate = squareSide?.toInt()!!
  23.     while (heightEstimate <= height?.toInt()!!) {
  24.         heightCount++
  25.         heightEstimate += squareSide?.toInt()!!
  26.     }
  27.     var totalFittingSquares = 0
  28.     for (num in 1..widthCount) {
  29.         totalFittingSquares += heightCount
  30.     }
  31.     return totalFittingSquares
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement