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
1) Recursive Approach to find factorial of a number
In recursion, we will call the same method multiple times until a condition is not satisfied.
Here, we will call the function factorial(n) in the following way:
Program:
Output
2) Iterative approach to find factorial of a number
In iteration, we will loop over a sequence of numbers and multiply the number to result variable to find factorial.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer