Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main(args: Array<String>) {
- print("Enter width: ")
- val width = readLine()
- print("Enter height: ")
- val height = readLine()
- print("Enter square side: ")
- val squareSide = readLine()
- val numOfSquares = countFittingSquares(width, height, squareSide)
- println(numOfSquares)
- }
- fun countFittingSquares(width: String?, height: String?, squareSide: String?): Int {
- var widthCount = 0
- var widthEstimate = squareSide?.toInt()!!
- while (widthEstimate <= width?.toInt()!!) {
- widthCount++
- widthEstimate += squareSide?.toInt()!!
- }
- var heightCount = 0
- var heightEstimate = squareSide?.toInt()!!
- while (heightEstimate <= height?.toInt()!!) {
- heightCount++
- heightEstimate += squareSide?.toInt()!!
- }
- var totalFittingSquares = 0
- for (num in 1..widthCount) {
- totalFittingSquares += heightCount
- }
- return totalFittingSquares
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement