Kotlin Program:

- To toggle string cases

Example:

User Input: heLLo WoRLd

Output: HEllO WOrlD

import java.util.Scanner
fun main(args: Array&llt;String>) {

    val s1:String
    var s2:String=""
    val userInput = Scanner(System.`in`)
    print("Enter your string : ")
    s1 = userInput.nextLine()
  for(i in 0..s1.length-1) {
    if(s1[i]>='a' && s1[i]<='z')
      s2+=s1[i].toUpperCase()
    else if(s1[i]>='A' && s1[i]<='Z')
      s2+=s1[i].toLowerCase()
    else
      s2+=s1[i]
  }
    println("After toggle, Your string  : $s2")
}

Output:

  Enter your string : Have good DAy
  After toggle, Your string : hAVE GOOD daY
Program
string

You should know first :

Lowercase alphabets : Starts from a (97) to z (122)

Uppercase alphabets : Starts from A (65) to z (90)


Main Logic:

We are using 2nd variable s2 to store the toggled string

for(i in 0..s1.length-1) {
  if(s1[i]>='a' && s1[i]<='z') {     //Check for lowercase
    s2+=s1[i].toUpperCase()  //convert it to uppercase & store it
  }
  else if(s1[i]>='A' && s1[i]<='Z') {    //Check for uppercase
    s2+=s1[i].toLowerCase()     //covert it to lowercase & store it
  }
  else {
    s2+=s1[i]   //Save character other than alphabets
  }
}
//Finally, print s2 variable
Concept

Coming Soon !

Quick
Tutorial

Quote

You cannot have a positive life and a negative mind.