Given two numbers, we have to swap them.
Example:
Input:
First number: 10
Second number: 20
Output:
First number: 20
Second number: 10
To swap two numbers – here we are using third variable/temporary variable (consider – first contains the first number, second contains the second number and temp is a temporary variable).
- Assign the first number (first) to the temporary variable (temp)
- Now, assign the second number (second) to the variable first.
- Now, assign the temp (that contains the first number) to the second.
- Finally, values are swapped, print them on the screen.
Program to swap two numbers in Kotlin
Output
need an explanation for this answer? contact us directly to get an explanation for this answer