Android Basics: Introduction to Kotlin Quiz Answers

Introduction to kotlin Quiz 1

  1. What is a program?

A specific task

A tool that helps you write Kotlin code

A series of instructions that a computer system executes to accomplish some action

A defined set of instructions that tells your computer to print “Happy Birthday!”

2. Which keyword do you use to define a function in Kotlin?

fun

func

function

newFunction

main

3.Which of the following do you need to create a Kotlin program that prints a line of text?
Choose as many answers as you see fit.

comment describing what your program does

a main() function

curly braces {} around the instructions to the system

a call to print() or println()

a piece of text surrounded by quotation marks

4.What do you expect this Kotlin code to do?

fun main(args: Array) {
println(“Hello, world!”)
println(“It’s a sunny and warm day!”)
}

Print one line of text

Print two lines of text

Print three lines of text

Print two lines of text separated by a blank line

5.How would you modify this main() function so that it prints a 6-layer cake for someone’s 4th birthday?

fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}

Set val age to 6, set val layers to 4

Set val age to “4”, set val layers to “6”

Set val age to 4, set val layers to 6

Leave the code as-is

6. Which of these options correctly calls the function, below, and passes it valid input arguments?

fun createMessage(name: String, location: String, age: Int) {
println(“My name is ${name}. I am from ${location}, and I am ${age} years old.”)
}

createMessage(“Amy”, “Australia”, 20)

createMessage(“Evan”, England, 9)

createmessage(“Tom”, “Thailand”, “40”)

createMessage(Heather, “Haiti”, 7)

Leave a Reply

Your email address will not be published. Required fields are marked *