Monday, 11 March 2013

29.Program for swap (input from user)



import java.util.*;
class perform
{
            int a,b;
            double c,d;
            void func(int m,int n)
            {
                        a=m;
                        b=n;
                        a=a+b;
                        b=a-b;
                        a=a-b;
                        System.out.println("Integer swap:"+a+","+b);
            }
            void func(double p,double q)
            {
                        c=p;
                        d=q;
                        c=c+d;
                        d=c-d;
                        c=c-d;
                        System.out.println("Float swap:"+c+","+d);
            }
}
class swap3
{
            public static void main(String args[])
            {
                        Scanner sc=new Scanner(System.in);
                        perform ob=new perform();
                        System.out.println("Enter integer no.:");
                        int m=sc.nextInt();
                        int n=sc.nextInt();
                        System.out.println("Enter float no.:");
                        double p=sc.nextDouble();
                        double q=sc.nextDouble();
                        ob.func(m,n);
                        ob.func(p,q);
            }
}

No comments:

Post a Comment