Swaping without using third or temp variable and wihout using + operator in java ~ VirusWorkshop

Tuesday, 23 July 2013

import java.io.*;
class swap
{
    public static void main(String s[]) throws IOException
    {
        int a=0,b=0;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter value of a : ");
        a = Integer.parseInt(br.readLine());
        System.out.print("Enter value of b : ");
        b = Integer.parseInt(br.readLine());
        System.out.println("Before Swaping");
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        a=a*b;
        b=a/b;
        a=a/b;
        System.out.println("After Swaping");
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
    }
save as swap.java

Author :

I am Unknown (Virus is my NickName).I Created this blog to share my Knowledge about Computers.Currently Studing in Third year BCA.Thanks for your visit.Please leave comments and suggestions.
Categories:

0 comments:

Post a Comment

Subscribe to RSS Feed Like me on FaceBook