Write A Java Program To Swap Two Numbers Using The Third Variable?

Write A Java Program To Swap Two Numbers Using The Third Variable?


Write A Java Program To Swap Two Numbers Using The Third Variable.

import java.util.Scanner;

public class Swap TwoNumbers {

      public static void main(string[ ] args)  {
      int x,y,temp;
      System.out.println("Enter x and y");
      Scanner in = new Scanner(system.in);
      x = in.nextInt( );
      y = in.nextIn( );
      System.out.println("Before Swapping:" + x + y);
      temp=x;
      x = y;
      y = temp;
      System.out.println("After Swapping:" + x + y);
    }

{

Output:

Enter x and y
45
98
Before Swapping: 4598
After Swapping: 9845

For more java interview questions visit www.fresher-naukri.com.

0 comments 10:

Post a Comment