Add two numbers in Scala - The Coding Shala

Home >> Learn Scala >> Add Two Numbers

 In this post, we will learn how to write a Scala program to Add Two Numbers.

Add Two Numbers in Scala

The following is the Scala program to Add two Numbers.

Scala Program: 

//add two numbers in scala
//the coding shala
object Main {
  def main(args: Array[String]){
    //we can take user input also
    val num1 = 10;
    val num2 = 20;
    
    //add both numbers
    val result = num1 + num2;
    println("Sum of " + num1 + " + " + num2 + " = " + result);
  }
}


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

Time Complexity, Space Complexity, Asymptotic Notations - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Java Method Overloading - The Coding Shala

Graph Representation using Adjacency Matrix - The Coding Shala

Sort an Array According to Count of 1(set) bits - The Coding Shala