Greeting with birth year calculation

Report a typo

Write a program that takes a person's name and age as input, and prints a greeting message using string templates. The message should include the person's name and the year they were born, assuming the current year is 2023.

Sample Input 1:

Alice
25

Sample Output 1:

Hello Alice! You were born in the year 1998.

Sample Input 2:

Bob
12

Sample Output 2:

Hello Bob! You were born in the year 2011.
Write a program in Kotlin
fun main() {
// Read the person's name and age from the console
val name = readln()
val age = readln().toInt()

// Calculate the birth year
val birthYear = 2023 - age

// Print the greeting message using string templates

}

Create a free account to access the full topic