Last active
December 27, 2017 01:44
-
-
Save ghtali/51ddc1b738eead34985dea0e356df8fb to your computer and use it in GitHub Desktop.
Passing parameters by value in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method; | |
public class Example { | |
public static void main(String[] args) { | |
int a = 30; | |
int b = 45; | |
System.out.println("Before swapping, a = " + a + " and b = " + b); | |
// Invoke the swap method | |
swapFunction(a, b); | |
System.out.println("\n**Now, Before and After swapping values will be same here**:"); | |
System.out.println("After swapping, a = " + a + " and b is " + b); | |
} | |
private static void swapFunction(int a, int b) { | |
// TODO Auto-generated method stub | |
System.out.println("Before swapping(Inside), a = " + a + " b = " + b); | |
// Swap n1 with n2 | |
int c = a; | |
a = b; | |
b = c; | |
System.out.println("After swapping(Inside), a = " + a + " b = " + b); | |
} | |
} | |
// A personal training, source: https://www.tutorialspoint.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment