scala

import scala.io.StdIn.readLine

object Calculator {
	def add(a: Int,b: Int): Int = a + b
	def subtract(a: Int,b: Int): Int = a - b
	def multiply(a: Int,b: Int): Int = a * b
	def divide(a: Int,b: Int): Double = a.toDouble / b.toDouble

	def main(argc: Array[String]): Unit = {
		println("Wlcome to the Scala Calculator")

		println("Enter first No. : ")
		val num1 = readLine().toInt
		
		println("Enter second No. : ")
		val num2 = readLine().toInt
		
		println("Choose an operation ( + , - , * ,/ ) : ")
		val op = readLine()

		val result = op match {
		
			case "+" => s"$num1 + $num2 = ${add(num1,num2)}"
			case "-" => s"$num1 - $num2 = ${subtract(num1,num2)}"
			case "*" => s"$num1 * $num2 = ${multiply(num1,num2)}"
			case "/" => 
				if (num2 == 0) "Division by zero is not allowed."
				else s"$num1 / $num2 = ${divide(num1,num2)}"
			case _ => "Invalid Operation Selected"
		}
		println(result)

	}
}
name := "Calculator"

version := "0.1"

scalaVersion := "2.13.12"

Leave a Reply

Your email address will not be published. Required fields are marked *

  • K2-18b: The second earth?!

    Alien Burps, Cosmic Oceans & A Planet That Might Be a Giant Jacuzzi Imagine a planet 124 light-years away that might be bubbling with lifeโ€”minus the WiFi and coffee shops. Enter K2-18b, a mysterious exoplanet hanging out in the constellation Leo, now famous…

  • Can we use Quantum Computing for Searching the Alien Life?

    Humans are obsessed with finding extraterrestrial life. From sci-fi movies to conspiracy theories about Area 51, weโ€™ve spent decades wondering if weโ€™re alone in the universe. But despite our best efforts, ET seems to be playing an epic game of hide-and-seek. Enter quantum…

  • Planetary Alignment in January 2025: why this celestial tea is piping hot ?

    The night sky is serving looks this January, and weโ€™re all invited to the ultimate glow-up party hosted by our solar system. Thatโ€™s right, a rare planetary alignment is happening, and itโ€™s giving main character energy. Letโ€™s talk about why this celestial tea…

  • Meet the Baby Planets: PDS 70b and PDS 70c

    PDS 70: A Star Forming Planets Before Our Eyes Imagine witnessing the birth of an entire planet. Thatโ€™s exactly what astronomers are observing in the PDS 70 system, a cosmic nursery located 370 light-years away in the constellation Centaurus. This young star system…