KIT MotoneAdachi Batch 7 - SMART PHONE APP DEVELOP

Run Settings
LanguageKotlin
Language Version
Run Command
/* 1. When would you choose for loop in your programs? Use when the number of loops has been determined. 2. When would you choose while loop in your program? Use this when the number of loops has not been determined. 3. When would you choose do while loop in your program? Also on 4. Write a program to input a number and find the sum of given number using while loop. 5. Write a program to input a number and find the sum of given number using do while loop. 6. Write a program to input a number and display the odd and even numbers using while and do while loop */ fun main(args : Array<String>){ // 4 var input = readLine()!!.toInt() var memo = 0 var result = 0 while (true) { ++memo result += memo if (memo == input) { break } } println(result) // 5 input = readLine()!!.toInt() memo = 0 result = 0 do { ++memo result += memo if (memo == input) { break } } while (true) println(result) // 6 input = readLine()!!.toInt() // even memo = 0 while (true) { ++memo if (memo % 2 != 0) { println("even $memo") } if (memo == input) { break } } // odd memo = 0 do { ++memo if (memo % 2 == 0) { println("odd $memo") } if (memo == input) { break } } while (true) }
Editor Settings
Theme
Key bindings
Full width
Lines