Value Interchange using Java Program

Code:

import java.util.Scanner;

public class Interchange
{
       public static void main(String[] args)
       {
              int a,b;

              Scanner sc = new Scanner(System.in);

              System.out.print("\nEnter The Value Of a : ");
              a=sc.nextInt();

              System.out.print("\nEnter The Value Of b : ");
              b=sc.nextInt();

              System.out.println("\na = "+a+",b = "+b);

              a=a+b;
              b=a-b;
              a=a-b;

              System.out.println("\nAfter Interchange");

              System.out.println("\na = "+a+",b = "+b+"\n");
        }
}

Output of program:

No comments

Powered by Blogger.