Scala - Find the largest number among three numbers using nested 'IF' statements Code Example

The code for Find the largest number among three numbers using nested 'IF' statements

// Scala program to find the largest number among three number 
// using nested "IF" statements

object Sample{  
  def main(args:Array[String]){  
    var num1:Int = 0;
    var num2:Int = 0;
    var num3:Int = 0;
    var large:Int = 0;
    
    print("Enter Number1:")
    num1=scala.io.StdIn.readInt()
    
    print("Enter Number2:")
    num2=scala.io.StdIn.readInt()
    
    print("Enter Number3:")
    num3=scala.io.StdIn.readInt()
    
    large = num3
    
    if(num1>num2){
      if(num1>num3){
        large=num1
      }
      else{	
        large=num3
      }
    }
    else if(num2>num3){
      large=num2
    }
    
    printf("%d is largest among 3 numbers\n",large)
  }
}


/*
Output:
Enter Number1:10
Enter Number2:30
Enter Number3:20
30 is largest among 3 numbers
*/
Code by IncludeHelp, on August 12, 2022 23:17

Comments and Discussions!

Load comments ↻






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