Posts

Data types in kotlin

  package com.example.my_kotlin_practice fun main (args: Array<String>) { // Kotlin built in data type can be categorized as follows: // // Number // Character // String // Boolean // Array var a : Int = 10000 var d : Double = 100.00 var f : Float = 100.00f var l : Long = 1000000004 var s : Short = 10 var b : Byte = 1 println ( "Int value is : $ a " ) println ( "Double value is : $ d " ) println ( "Float value is : $ f " ) println ( "Long value is : $ l " ) println ( "Short value is : $ s " ) println ( "Byte value is : $ b " ) // Kotlin character data type is used to store a single character, and they are represented by the type Char keyword. // A Char value must be surrounded by single quotes, like 'A' or '1'. var letter : Char = 'A' println ( "Character value is : $ letter " ) // Kotlin supports a number...

Variables in kotlin

  package com.example.my_kotlin_practice fun main (args: Array<String>) { var name = "Helle World" var age = 22 var height = 8 println (name) println (age) println (height) // variable values using $ sign println ( "Name : $ name " ) println ( "Age : $ age " ) println ( "Height : $ height " ) // variable values without using $ sign println ( "Name : " + name) println ( "Age : " + age) println ( "Height : " + height) // Mutable variables name = "How are you ?" age = 24 println ( "Name : $ name " ) println ( "Age : $ age " ) // Read-only variables /* A read-only variable can be declared using val (instead of var) and once a value is assigned, * it can not be re-assigned */ val bat : String = "Tomorrow" val toy : Int = 20 println ( "Bat : $ bat " ) println ( ...

Kotlin Comments

  package com.example.myapplication fun main (args: Array<String>) { // This is single line comment and I have shown simple "Hello World" as shown below println ( "Hello world!" ) // This is also a single line comment /* A multi-line comment in Kotlin starts with /* and end with */. So any text written in between /* and */ will be treated as a comment and will be ignored by Kotlin compiler. Multi-line comments also called Block comments in Kotlin.*/ /* This is a multi-line comment, and it can span * as many lines as you like */ println ( "Above shown is multi-line comments" ) /* This is a multi-line comment, and it can span * as many lines as you like /* This is a nested comment */ // Another nested comment */ println ( "Above shown is kotlin nested comments" ) } OUTPUT : Hello world! Above shown is multi-line comments Above shown is kotlin nested comments Process finished with exit c...

Kotlin basic syntax

  package com.example.myapplication fun main (args: Array<String>) { println ( "Hello World" ) println ( 20 ) println ( 20 + 20 ) var string12 : String = "Hello kotlin, how are you ?" println (string12)      println ( "Hello, World!" )      println ( "Hello" )      println ( "Whole world!" )      print ( "How are you ?" )      println ( " Next time we will meet!" )      println ( 200 )      println ( "200" )      println ( 2 + 2 )      println ( 4 * 3 )      println ( "I am without semi-colon" )      println ( "I am with semi-colon" );      println ( "1" ); println ( "2" ) } OUTPUT : Hello, World! Hello Whole world! How are you ? Next time we will meet! 200 200 4 12 I am without semi-colon I am with semi-colon 1 2 Process finished with exit code 0