-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalGlobal.java
More file actions
46 lines (36 loc) · 1 KB
/
LocalGlobal.java
File metadata and controls
46 lines (36 loc) · 1 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner; // for input
public class LocalGlobal
{
// Data Members
int a, b;
// Member functions / methods
void swap(LocalGlobal obj) // for every unique object
{
int temp;
temp = obj.a;
obj.a = obj.b;
obj.b = temp;
}
void output() // unique output for every object
{
System.out.println(" a : " + a);
System.out.println(" b : " + b);
}
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
LocalGlobal dani = new LocalGlobal(); // object made of main class
System.out.print(" Enter 1st Number : ");
dani.a = obj.nextInt();
System.out.print(" Enter 2nd Number : ");
dani.b = obj.nextInt();
System.out.println(" BEFORE SWAPPING");
dani.output();
// SWAPPING
dani.swap(dani);
System.out.println(" AFTER SWAPPING");
dani.output();
// closing Scanner object
obj.close();
}
}