Friday, April 1, 2016

Java : creatng swaping function

package blog_swap;
import java.util.Scanner;
public class Blog_swap {
    /**
     * Author #Jacob Kurian#
     */
    public static void main(String[] args) {
    Scanner input =  new Scanner(System.in);

    int x;
    int y;
    int temp;

        System.out.println("Here is the swap function");
        System.out.println("-------------------------");
        System.out.print("Enter value of x: ");
        x = input.nextInt();
        System.out.print("Enter value of y: ");
        y = input.nextInt();
        System.out.println("Details: x =" + x + ", y = " + y);
        temp = x;
        x = y;
        y = temp;
        System.out.println("After values swapped");
        System.out.println("Details: x =" + x + ", y = " + y);
    }
}

No comments:

Post a Comment