public static void swap(int num1, int num2){
int temp = num1;
num1 = num2;
num2 = temp;
}
public static void main(String args[]) {
int x1 = 5; int x2 = 7;
swap(x1,x2); //<--Code is here
}
graph TD
subgraph main
B(x1 = 5)
C(x2 = 7)
end
public static void swap(int num1, int num2){
int temp = num1; //<--Code is here
num1 = num2;
num2 = temp;
}
public static void main(String args[]) {
int x1 = 5; int x2 = 7;
swap(x1,x2);
}
graph TD
subgraph main
B(x1 = 5)
C(x2 = 7)
end
subgraph swap
E(num1 = 5)
F(num2 = 7)
end
public static void swap(int num1, int num2){
int temp = num1;
num1 = num2;
num2 = temp; //<--Code is here
}
public static void main(String args[]) {
int x1 = 5; int x2 = 7;
swap(x1,x2);
}
graph TD
subgraph main
B(x1 = 5)
C(x2 = 7)
end
subgraph swap
E(num1 = 7)
F(num2 = 5)
end
public static void swap(int num1, int num2){
int temp = num1;
num1 = num2;
num2 = temp;
}
public static void main(String args[]) {
int x1 = 5; int x2 = 7;
swap(x1,x2); //<--Code returns here
}
graph TD
subgraph main
B(x1 = 5)
C(x2 = 7)
end
Point x1 = new Point(1,2); Point x2 = new Point(5,6);
swap(x1,x2);
graph TD
subgraph main
B(x1) --> D(1,2)
C(x2) --> E(5,6)
end
public static void swap(Point p1, Point p2){
Point temp = p1; //CODE IS HERE
p1 = p2;
p2 = temp; }
graph TD
subgraph main
B(x1) --> D(1,2)
C(x2) --> E(5,6)
end
subgraph swap
G(p1)
H(p2)
end
G --> D
H --> E
public static void swap(Point p1, Point p2){
Point temp = p1;
p1 = p2;
p2 = temp; //CODE IS HERE }
graph TD
subgraph main
B(x1) --> D(1,2)
C(x2) --> E(5,6)
end
subgraph swap
G(p1)
H(p2)
end
G --> E
H --> D
Point x1 = new Point(1,2); Point x2 = new Point(5,6);
swap(x1,x2); //Method returns, no change in x1 or x2
graph TD
subgraph main
B(x1) --> D(1,2)
C(x2) --> E(5,6)
end
Point x1 = new Point(1,2); Point x2 = new Point(5,6);
swap(x1,x2); //About to invoke swap
graph TD
subgraph main
B(x1) --> D(1,2)
C(x2) --> E(5,6)
end
public static void swap(Point p1, Point p2){
Point temp = (Point)p1.clone(); //Deep Copy
p1.x = p2.x; p1.y = p2.y;
p2.x = temp.x; p2.y = temp.y;
}
graph TD
subgraph main
A(x1) --> B(1,2)
C(x2) --> D(5,6)
end
subgraph swap
E(p1)
F(p2)
end
E --> B
F --> D
public static void swap(Point p1, Point p2){
Point temp = (Point)p1.clone(); //<-- This line Executed
p1.x = p2.x; p1.y = p2.y;
p2.x = temp.x; p2.y = temp.y;
}
graph TD
subgraph main
A(x1) --> B(1,2)
C(x2) --> D(5,6)
end
subgraph swap
E(p1)
F(p2)
G(temp) --> H(1,2)
end
E --> B
F --> D
public static void swap(Point p1, Point p2){
Point temp = (Point)p1.clone();
p1.x = p2.x; p1.y = p2.y; //<-- This line Executed
p2.x = temp.x; p2.y = temp.y;
}
graph TD
subgraph main
A(x1) --> B(5,6)
C(x2) --> D(5,6)
end
subgraph swap
E(p1)
F(p2)
G(temp) --> H(1,2)
end
E --> B
F --> D
public static void swap(Point p1, Point p2){
Point temp = (Point)p1.clone();
p1.x = p2.x; p1.y = p2.y;
p2.x = temp.x; p2.y = temp.y; //<-- This line Executed
}
graph TD
subgraph main
A(x1) --> B(5,6)
C(x2) --> D(1,2)
end
subgraph swap
E(p1)
F(p2)
G(temp) --> H(1,2)
end
E --> B
F --> D
Point x1 = new Point(1,2); Point x2 = new Point(5,6);
swap(x1,x2); //Swap has returned
graph TD
subgraph main
A(x1) --> B(5,6)
C(x2) --> D(1,2)
end
Click the center of the target
Close window