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) Swapping two numbers using third variable
To swap two values, there is a simple approach is using a temporary variable that stores the element for swapping.
Algorithm:
Let, variable a contains first value, variable b contains second value and temp is the temporary variable.
Program:
Output
2) Swapping two numbers without using third variable
We can also swap two numbers without using the third variable. This method saves computation space hence is more effective.
Let, variable a contains first value, variable b contains second value.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer