Java program to swap two numbers

package com;

import java.util.Scanner;

class SwapNumbers
{
   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.nextInt();

      System.out.println("Before Swapping\nx = "+x+"\ny = "+y);

      temp = x;
      x = y;
      y = temp;

      System.out.println("After Swapping\nx = "+x+"\ny = "+y);
   }
}

Output:

Enter x and y
4 5
Before Swapping
x = 4
y = 5
After Swapping
x = 5

y = 4

No comments:

Post a Comment

What is Normalization?

Database normalization is a data design and organization process applied to data structures based on rules that help building relational dat...