-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNumberTest.java
More file actions
48 lines (41 loc) · 851 Bytes
/
NumberTest.java
File metadata and controls
48 lines (41 loc) · 851 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Scanner;
class Number{
private int x,y;
void getData(){
Scanner sc=new Scanner(System.in);
System.out.print("Enter value of x: ");
x=sc.nextInt();
System.out.print("Enter value of y: ");
y=sc.nextInt();
}
void setData(int x1, int y1){
x=x1;
y=y1;
}
void swap(){
int t;
t=x;x=y;y=t;
}
void display(){
System.out.println("x= " + x);
System.out.println("y= " + y);
}
}
class NumberTest{
public static void main(String args[]){
/*Number n1=new Number();
n1.setData(5,6);
System.out.println("values before swap!");
n1.display();
System.out.println("values after swap!");
n1.swap();
n1.display();*/
Number n2=new Number();
n2.getData();
System.out.println("values before swap!");
n2.display();
System.out.println("values after swap!");
n2.swap();
n2.display();
}
}