-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwap.java
More file actions
32 lines (25 loc) · 679 Bytes
/
Swap.java
File metadata and controls
32 lines (25 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.kunal;
public class Swap {
public static void main(String[] args) {
int a = 10;
int b = 20;
// swap numbers code
// int temp = a;
// a = b;
// b = temp;
swap(a, b);
System.out.println(a + " " + b);
String name = "Kunal Kushwaha";
changeName(name);
System.out.println(name);
}
static void changeName(String naam) {
naam = "Rahul Rana"; // creating a new object
}
static void swap(int num1, int num2) {
int temp = num1;
num1 = num2;
num2 = temp;
// this change will only be valid in this function scope only.
}
}