Scala - Ternary Operator (Print the division of student based on percentage) Code Example

The code for Ternary Operator (Print the division of student based on percentage)

// Scala program to print the division of student based 
// on percentage using ternary operator

object Sample{  
  def main(args:Array[String]){  
    var per:Float=0
    var result:String=""
    
    print("Enter percentage: ")
    per = scala.io.StdIn.readFloat()
    
    result = if (per>=60) "First Division" else if(per>=45&&per<60) "Second Division" else if(per>=33&&per<45) "Third Division" else "You are FAILD"
    
    println(result)
  }  
}


/*
Output:
Enter percentage: 82.34
First Division
*/
Code by IncludeHelp, on August 12, 2022 23:28

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.