Showing posts with label sum of two numbers in scala. Show all posts
Showing posts with label sum of two numbers in scala. Show all posts

Friday, August 18, 2017

Addition of Two Numbers in Scala

A very simple program that will ask the user to give two numbers and then our program will find the sum of the two numbers given by our user using Scala as our programming language. The code is some what similar in Java using Java Scanner to get inputs from our user. I hope you will learn something new using Scala. Thank you.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Listing

import java.util.Scanner;

object Add {

def main(args: Array[String]) {

var scanner = new Scanner(System.in);

println("\n\n");
print("Addition of Two Numbers in Scala");
println("\n\n");

print("Enter the first number : ");


var a = scanner.nextInt();

print("Enter the second number : ");

var b = scanner.nextInt();
println("\n\n");
println("The sum of " + a + " and " + b + " is " +(a+b) +".");
println("\n\n");
println("END OF PROGRAM");

}
}