How to Add Two Numbers in Scala

Add Two Numbers in Scala

In this example, we will show you how to add two numbers in scala program language. The sample program and output has been attached in the same post.

Example Code

import java.util.Scanner;

object Addition {
	
	def main(args: Array[String]) {
	
		// defining the scanner object
		var scanner = new Scanner(System.in);
	
		println("Enter the first number : ");
	
		// reading input from user
		var a = scanner.nextInt();
		
		println("Enter the second number : ");
		
		// reading input from user
		var b = scanner.nextInt();
		
		println("The Result is : "+(a+b));
		
	}
}

Output

Enter the first number :
20
Enter the second number :
30
The Result is : 50