Introduction fun main(args: Array) { val a: Int =

Introduction

Kotlin is a programming language
introduced by JetBrains.It is strongly statically typed language.It runs on
JVM. Google announced Kotlin is an official language for android development in
2017. It is an open source programming language that combines object-oriented
programming and functional features into a unique platform.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

 

Data Types

Data types available are:

 

Numbers

Following are
variable length datatype of numbers:

Double

64

Float

32

Long

64

Int

32

Short

16

Byte

8

 

 

 

fun main(args: Array) {   val a: Int = 200   val d: Double = 133.00   val f: Float = 120.00f   val l: Long = 1004564012   val s: Short = 5   val b: Byte =     }

 

Character

In
Kotlin character is represented using char. A character is declared
in a single quote like ‘a’. Variable are declared in two ways :”var” and
another “val”.

fun main(args: Array)
{

   val letter: Char    // defining a variable

   letter = ‘A’        // Assigning a value to it

}

String

Strings are character
arrays. They are immutable. There are two types of string: raw String and
escaped String.

 

Arrays

Arrays are a
collection of same type of data. Kotlin supports arrays of different data
types.

fun main(args: Array)
{

   val numArray: IntArray = intArrayOf(12, 23, 34,
42, 51)

   println(numbers2)

}

The above piece of
code yields the output:34

 

Collections

Collection is a part
of the data structure. There are two types of collection: immutable
collection (lists, maps and sets) & mutable collection (type
of it is editable).

Ranges

Ranges is unique
characteristic of Kotlin. It provides an operator that helps you iterate
through a range. It is implemented using rangeTo() .It uses
operator form as (..).

fun main(args: Array)
{

   val i:Int 
= 4

   for (j in 1..9)

   print(j) // prints “123456789”

  

   if (i in 1..10) { // equivalent of 1