import java.util.*;
class Main1
{
int a,b;
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
Main m=new Main();
System.out.println("Enter two number:");
m.a=sc.nextInt();
m.b=sc.nextInt();
System.out.println("Numbers are a="+m.a+"\tb="+m.b);
swap(m);
System.out.println("After returning from method \n numbers are a="+m.a+"\tb="+m.b);
}
static int swap (Main x)
{
int temp;
temp=x.a;
x.a=x.b;
x.b=temp;
System.out.println("After swapping in method\n numbers are a="+x.a+"\tb="+x.b);
}
}
class Main1
{
int a,b;
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
Main m=new Main();
System.out.println("Enter two number:");
m.a=sc.nextInt();
m.b=sc.nextInt();
System.out.println("Numbers are a="+m.a+"\tb="+m.b);
swap(m);
System.out.println("After returning from method \n numbers are a="+m.a+"\tb="+m.b);
}
static int swap (Main x)
{
int temp;
temp=x.a;
x.a=x.b;
x.b=temp;
System.out.println("After swapping in method\n numbers are a="+x.a+"\tb="+x.b);
}
}
No comments :
Post a Comment