Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views3 pages

Scala Program

The document contains several Scala programs demonstrating basic functionalities. These include printing 'Hello World', displaying a profile, performing addition, calculating squares and square roots, computing the area of a triangle, and swapping two numbers. Each program is structured with a main method and uses standard input/output for interaction.

Uploaded by

kshitijasingh24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Scala Program

The document contains several Scala programs demonstrating basic functionalities. These include printing 'Hello World', displaying a profile, performing addition, calculating squares and square roots, computing the area of a triangle, and swapping two numbers. Each program is structured with a main method and uses standard input/output for interaction.

Uploaded by

kshitijasingh24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a Scala program to print Hello World.

object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, World!")
}
}

2) Write a Scala program to print the Profile


object MyProfile {
def main(args: Array[String]): Unit = {
val name = "Tejas Mandravat"
val age = 25
val profession = "Software Developer"
val skills = List("Scala", "Java", "Python", "SQL")
val location = "India"

println("===== My Profile =====")


println(s"Name : $name")
println(s"Age : $age")
println(s"Profession : $profession")
println(s"Skills : ${skills.mkString(", ")}")
println(s"Location : $location")
println("=======================")
}
}

3) Write a Scala program to print Addition of two numbers


import scala.io.StdIn.readInt

object AddNumbers {
def main(args: Array[String]): Unit = {
print("Enter first number: ")
val num1 = readInt()

print("Enter second number: ")


val num2 = readInt()

val sum = num1 + num2


println(s"The sum of $num1 and $num2 is: $sum")
}
}

4) Write a Scala program to print Square of two numbers


mport scala.io.StdIn.readInt

object SquareNumbers {
def main(args: Array[String]): Unit = {
print("Enter first number: ")
val num1 = readInt()
print("Enter second number: ")
val num2 = readInt()

println(s"Square of $num1 is: ${num1 * num1}")


println(s"Square of $num2 is: ${num2 * num2}")
}
}

5) Write a Scala program to print Square root


import scala.io.StdIn.readDouble
import scala.math.sqrt

object SquareRootInput {
def main(args: Array[String]): Unit = {
print("Enter first number: ")
val num1 = readDouble()

print("Enter second number: ")


val num2 = readDouble()

println(s"Square root of $num1 is: ${sqrt(num1)}")


println(s"Square root of $num2 is: ${sqrt(num2)}")
}
}

6) Write a Scala program to print Area of triangle


import scala.io.StdIn.readDouble

object TriangleAreaInput {
def main(args: Array[String]): Unit = {
print("Enter base of the triangle: ")
val base = readDouble()

print("Enter height of the triangle: ")


val height = readDouble()

val area = 0.5 * base * height


println(s"Area of the triangle is: $area")
}
}

7) Write a Scala program to print Swapping two number


object Swap {
def main(args: Array[String]): Unit = {
var a = 5
var b = 10

println(s"Before swapping: a = $a, b = $b")


a=a+b
b=a-b
a=a-b

println(s"After swapping: a = $a, b = $b")


}
}

You might also like