Grokking Java Basics
Vote

0% completed

​

Swapping Two Elements

Problem Statement

Write a Java program to swap the values of two variables. For instance, if variable a holds the value 5 and variable b holds the value 10, after swapping, a should hold 10 and b should hold 5.

Examples

Example 1:

  • Input: a = 5, b = 10
  • Output: a = 10, b = 5
  • Justification: Values of variable a and b are swapped.

Example 2:

  • Input: a = 3.14, b = 2.71
  • Output: a = 2.71, b = 3.14
  • Justification: Values of variable a and b are swapped.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content