Basic Java Examples

Swap Numbers Java Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

7 Comments

  • This is crap code how can it be swap??
    once the function returns the variable will have their original values not the changed one.

    • Hello,

      As you commented that – main function num1 and num2 value wont change after executing swap function, because the scope for Main function is within in that block only and same for the Swap function, so after executing the Swap function, the scope will get finish there and control will return back to main, so no changes will be reflected in Main function.Therefore, Main function num1 and num2 value wont change after executing swap function.

      Regards,
      Usha Naidu.

Sponsors

Facebook Fans