TheBulgarianWolf

Kotlin If_else

Mar 13th, 2021
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.95 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2.     val number = -10
  3.  
  4.     val result = if(number > 0){
  5.         "Positive number"
  6.     }
  7.     else{
  8.         "Negative number"
  9.     }
  10.  
  11.     if(number > 0){
  12.         println("Positive number")
  13.     }
  14.     else{
  15.         println("Negative number")
  16.     }
  17.  
  18.     println(result)
  19.  
  20.     val a = -9
  21.     val b = -11
  22.  
  23.     val max = if(a > b){
  24.         println("$a is larger than $b")
  25.         println("max variable holds the value of a.")
  26.         a
  27.     }
  28.     else{
  29.         println("$b is larger than $a")
  30.         println("max variable holds the value of b.")
  31.         b
  32.     }
  33.     println("max = $max")
  34.  
  35.     val n1 = 3
  36.     val n2 = 5
  37.     val n3 = -2
  38.  
  39.     val max2 = if(n1 > n2){
  40.         if(n1 > n3){
  41.             n1
  42.         }
  43.         else{
  44.             n3
  45.         }}
  46.         else{
  47.             if(n2 > n3){
  48.                 n2
  49.             }
  50.             else{
  51.                 n3
  52.             }
  53.     }
  54.  
  55.     println(max2)
  56. }
Add Comment
Please, Sign In to add comment