Scala program to calculate the power of any number

How to calculate the power of any number in the Scala programming language. Lets us define three variable num for number, pow for power, and result in order to store the last result in it. Initialize all the values to 0.

object divinseo{
    def main(args: Array[String]){
        var num: Double = 0
        var pow: Double = 0
        var result: Double= 0
        Console.println("Enter the number: ")
        Console.println("Enter the power: ")
        println("Result is : "+result)

Take the value of the number and the value of power from the user. Pass both values to the function scala.math.pow(n,p), store the result in the result variable.


Enter the number: 4
Enter the power: 5
Result is : 1024.0

Leave a Comment