// Capitals.kt Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2023-04-29 File created. fun main() { val countries_and_capitals = "Finland Helsinki Usa Washington Denmark Copenhagen " + "Afghanistan Kabul Ukraine Kyiv England London " + "Italy Rome France Paris Spain Madrid " + "Portugal Lisbon Chile Santiago Japan Tokyo " + "Sweden Stockholm Norway Oslo Pakistan Islamabad " + "Iceland Reykjavik Hungary Budapest Holland Amsterdam " + "Belgium Brussels Austria Vienna Israel Jerusalem " print( "\n This program may know the capital of a country." + "\n Type in the name of some country: " ) var country_name = readLine()!!.lowercase() country_name = country_name.substring( 0, 1 ).uppercase() + country_name.substring( 1 ) val index_of_country_name = countries_and_capitals.indexOf( country_name ) if ( index_of_country_name != -1 ) { // The country name was found in countries_and_capitals var text_after_country_name = countries_and_capitals. substring( index_of_country_name + country_name.length ) // A space at the end of the string ensures that also // the last country-capital pair in the string works. text_after_country_name = text_after_country_name.trim() + " " val capital_name = text_after_country_name.substring( 0, text_after_country_name.indexOf( " " ) ) print( "\n The capital of " + country_name + " is " + capital_name + ".\n\n" ) } else { print( "\n No data about \"" + country_name + "\". Sorry.\n\n" ) } }