Scala Basic Programs
- Scala program to print \'Hello World\'
- Scala program to create the mutable variable
- Scala program to create an immutable variable
- Scala program to create different types of variables
- Scala program to print the value of variables using printf() function
- Scala program to print the value of the Boolean variable using printf() function
- Scala program to print the hexadecimal value of a number
- Scala program to print the octal value of a number
- Scala program to read and print the value of the string
- Scala program to read the value of integer variable
- Scala program to read the value of float variable
- Scala program to read the value of character variable
- Scala program to find the largest number between two numbers using ternary operator
- Scala program to find the largest number among three numbers using ternary operator
- Scala program to check whether a given number is EVEN or ODD using ternary operator
- Scala program to print the ASCII value of the corresponding character
- Scala program to swap two numbers
- Scala program to calculate the area of the circle
- Scala program to calculate the perimeter of the circle
- Scala program to calculate the area of the rectangle
- Scala program to find the square root of a number
- Scala program to calculate the power of a number
- Scala program to multiply two numbers using the plus (+) operator
- Scala program to calculate the Highest Common Factor (HCF)
- Scala program to demonstrate the bitwise left-shift (<<) operator
- Scala program to demonstrate the bitwise right-shift (>>) operator
- Scala program to demonstrate the Bitwise AND (&) Operator
- Scala program to demonstrate the Bitwise AND (&) Operator
- Scala program to demonstrate the Bitwise OR (|) Operator
- Scala program to demonstrate the Bitwise XOR (^) Operator
- Scala program to demonstrate the 1\'s complement (~) Operator
- Scala program to find factorial of a number
Program/Source Code:
The source code to calculate the area of the circle is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
Output:
Explanation:
In the above program, we used an object-oriented approach to create the program. Here, we created an object Sample. We defined main() function. The main() function is the entry point for the program.
In the main() function, we created two float variables radius, area, that are initialized with 0. Then we read the value of radius from the user and calculate the area of the circle. After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer