@Assessment

Unary

November 25, 2022 · Kotlin
fun main() {
  var a = true
  var b = false
  println(!a)
   println(!b)
 }
 

string

November 25, 2022 · Kotlin
fun main(){
    var name = "Compiler"
    for (x in name){
        println(x)
    }
}

array

November 25, 2022 · Kotlin
fun main(){
    var fruits = arrayOf("apple", "banana", "orange", "mango")
    for (x in fruits){
        println(x)
    }
}

Variable

November 25, 2022 · Kotlin
fun main(){
    val num = 55
    println(num)
    println("My mark is $num")
    println("Total mark is ${num*num}")
}

Function

November 25, 2022 · Kotlin
fun sum (a:Int, b:Int) = a + b

fun main(){
    var result = sum ( 10, 15 )
    println(result)
}

String

November 25, 2022 · Kotlin
fun main() {
   var fruit1:String = "Apple" 
   var fruit2:String = "Banana"
   println(fruit1 + " " + fruit2)
   println(fruit1.contains(fruit2))
   println(fruit1.toLowerCase())
   println(fruit2.toUpperCase())
}

Array

November 25, 2022 · Kotlin
fun main() {
   var fruits = arrayOf("apple", "banana", "orange", "mango")
   println(fruits.contentToString())
   println(fruits.size)
   println(fruits[1])
}

Down to and Step range

November 25, 2022 · Kotlin
fun main() {
   for( d in 500 downTo 400 step 5){
       println(d)
   }
}

Step range

November 25, 2022 · Kotlin
fun main() {
   for( c in 0..100 step 10){
       println(c)
   }
}

Down to range

November 25, 2022 · Kotlin
fun main() {
   for( b in 50 downTo 0){
       println(b)
   }
}

Simple range

November 25, 2022 · Kotlin
fun main() {
   for( a in 0..10){
       println(a)
   }
}

While

November 25, 2022 · Kotlin
fun main() {
    var number = 1305
    var i = 1
    var add = 0
    while (i <= number) {
        add += i
        i++
    }
    println("Sum = $add")
}

When

November 25, 2022 · Kotlin
fun main(){
    var month = 15
    var result = when(month){
        1-> "jan"
        2-> "feb"
        3-> "mar"
        4-> "apl"
        5-> "may"
        6-> "jun"
        7-> "jly"
        8-> "aug"
        9-> "sep"
       10-> "oct"
       11-> "nov"
       12-> "dec"
       else-> "Invalid"
    }
    println(result)
}

If - else

November 25, 2022 · Kotlin
fun main() {
var a = 25 
var b = 35
if (a+b > 0 ){
    println("a and b is a positive number ")
}else{
    println("a and b is a negative number")
}
}

Type Conversion

November 25, 2022 · Kotlin
fun main() {
var a:String = "10"
var b = a.toInt()
println(b)

var c:Int = 30
var d = c.toString()
println(d)

var e:String = "hai"
var f = e.toBoolean()
println(f)

var g:Boolean = true
var h = g.toString()
println(h)

var i:Double = 2.3
var j = i.toInt()
println(j)

var k:Int = 4
var l = k.toDouble()
println(l)
}

Logical Operators

November 25, 2022 · Kotlin
fun main() {
  var a = 25
  println(a>20 && a<10)
  println(a>10 || a<5)
  println(!(a>10))
}

Comparison and Equality

November 25, 2022 · Kotlin
fun main() {
  var a = 10
  var b = 20
  println(a>b)
  println(a<b)
  println(a>=b)
  println(a<=b)
  println(a==b)
  println(a!=b)
}

Increment and Decrement Operators

November 25, 2022 · Kotlin
fun main() {
  var a = 10
  println(+a)
   println(++a)
  println(-a)
   println(--a)
 }
 

Assignment Operators

November 25, 2022 · Kotlin
fun main() {
   var x = 40
   x += 5
   println("x += 5 = " + x )
   x -= 5
   println("x -= 5 = " +  x)
   x *= 5
   println("x *= 5 = " +  x)
   x /= 5
   println("x /= 5 = " +  x)
   x %= 5
   println("x %= 5 = " + x)
}

Concatenation

November 25, 2022 · Kotlin
fun main(){
    val fname = "John"
    val lname = "Deo"
    println(fname+ " " +lname)
}