Scala Arithmetic Operators Example

Scala Arithmetic Operators Example

In this example, we will show you scala arithmetic operators examples.

Example Code

import java.util.Scanner;

object ArithmaticExample {
	
	def add(a: Int, b: Int): Int = {
		
		return a + b;
	}
	
	def sub(a: Int, b: Int): Int = {
		
		return a - b;
	}
	
	def mul(a: Int, b: Int): Int = {
		
		return a * b;
	}
	
	def div(a: Int, b: Int): Int = {
		
		return a / b;
	}
	
	def mod(a: Int, b: Int): Int = {
		
		return a % b;
	}

	def main(args: Array[String]) {
	
		var scanner = new Scanner(System.in);
			
		println("Enter the first number : ");	
		var a = scanner.nextInt();
		
		println("Enter the second number : ");	
		var b = scanner.nextInt();
	
		println("Addition : "+add(a, b));
		println("Subtraction : "+sub(a, b));
		println("Multiplication : "+mul(a, b));
		println("Division : "+div(a, b));
		println("Modulus : "+mod(a, b));
	}
}

Output

Enter the first number :
50
Enter the second number :
3
Addition : 53
Subtraction : 47
Multiplication : 150
Division : 16
Modulus : 2

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.