KIT MotoneAdachi Batch 7 - SMART PHONE APP DEVELOP

Run Settings
LanguageKotlin
Language Version
Run Command
/* Analyze the questions and write proper definition and example code for the following: (5 X 2 = 10) 1. What are control structures? 2. What are conditional constructs? 3. What are looping constructs? 4. Write a program to get input for 4 numbers and find the smallest among all using if expression. 5. Write a program to input a character and print whether it is vowel or consonant using when expression. (1 X 10 = 10) 6. Write the different variations of for loop using suitable example programs. */ fun main (args : Array<String>) { // control structures I will explain these in the following code and comments... var answerNum: Int = 0 var answerStr: String = "" var answerChar: Char = ' ' for (i in 0..9) { // looping constructs Run from 0 to 9. The value is assigned to variable i in each loop. println("Q$i Are you busy? [Y/n]") answerStr = readLine().toString() if (answerStr == "Y") { // conditional constructs? Checking whether variable answerStr is "Y". println("Let's go to bed.") } else { println("Let's do your work.") } } // Write a program to get input for 4 numbers and find the smallest among all using if expression. // In four loops with "for", "if" determines whether the input value is smaller than the previous value. var min = 0 for (i in 1..4) { println("$i/4 Plz enter number.") answerStr = readLine().toString() if (!answerStr.isNullOrBlank()) { answerNum = answerStr.toInt() println(answerStr) if (i == 1 || min > answerNum) { min = answerNum } } else { println("oops...") } } println("min: $min") // Write a program to input a character and print whether it is vowel or consonant using when expression. println("Plz enter a any string.") answerChar = readLine()!![0] // This "when" has all vowels set. This is possible than this code to determine whether the input word is a vowel. when (answerChar) { in "a" -> println("vowel") in "i" -> println("vowel") in "u" -> println("vowel") in "e" -> println("vowel") in "o" -> println("vowel") else -> println("consonant or not voewl") } // Write the different variations of for loop using suitable example programs. for (i in 0..9) { println(i) } var i = 0 while (true) { ++i println(i) if (i == 10) { break } } i = 0; do { ++i println(i) if (i == 10) { break } } while (true) }
Editor Settings
Theme
Key bindings
Full width
Lines