Copyrights Holder

Document Notice and License:

This work is being provided by the copyright holders under the following license.

By obtaining and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions.

Permission to copy, modify, and distribute this work, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the work or portions thereof, including modifications:

  • The full text of this NOTICE in a location viewable to users of the redistributed or derivative work.
  • Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, the W3C Software and Document Short Notice should be included.
  • Notice of any changes or modifications, through a copyright statement on the new code or document such as "This software or document includes material copied from or derived from [title and URI of the W3C document]. Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."

THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.

COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.

The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the work without specific, written prior permission. Title to copyright in this work will at all times remain with copyright holders.

Comments

Popular

Text/Html

Data Protection Terms

Link

Some Preview

Android Developers menu Your first program in Kotlin Sign in access_time13 mins remaining Before you begin Get started Open Kotlin Playground Run your first program Parts of a function Modify your program Kotlin style guide Fix errors in your code Exercises Solutions Conclusion 10. Solutions The output of the program is: 1 2 3 The code in your program should look like: fun main() { println("I'm") println("learning") println("Kotlin!") } This is the correct code for the program: fun main() { println("Monday") println("Tuesday") println("Wednesday") println("Thursday") println("Friday") } The closing curly brace that indicates the end of the function body for the main function is missing on the third line of the program. Correct code: fun main() { println("Tomorrow is rainy") } Output: Tomorrow is rainy When you run the program, you see an Unresolved reference: printLine error. This is because printLine() isn't a recognized function in Kotlin. You can also see the part of the code causing the error highlighted in red in the Kotlin Playground. Change the function name to println to print a line of text to the output, which fixes the error. Correct code: fun main() { println("There is a chance of snow") } Output: There is a chance of snow When you run the program, you see an Unresolved reference: println error. This message doesn't directly say how to fix the problem. This can sometimes happen when you troubleshoot an error, and it requires you to take a deeper look at the code to resolve the unexpected behavior. Upon closer look, the second println() function call in the code is red, which signals that's where the problem is. Kotlin expects just one statement on each line. In this case, you can move the second and third println() function calls onto separate new lines to solve the issue. Correct code: fun main() { println("Cloudy") println("Partly Cloudy") println("Windy") } Output: Cloudy Partly Cloudy Windy If you run the program, you see the error: Function 'main' must have a body. A function body should be enclosed within an opening curly brace and a closing curly brace { }, not opening and closing parentheses ( ). Correct code: fun main() { println("How's the weather today?") } Output: How's the weather today? Back English Next bug_report Report a mistake Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. The new page has loaded.

Website Training