Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

java program to swap two numbers

import java.util.Scanner;


public class Practice{

     public static void main(String[] args)

     {

        Scanner sc = new Scanner(System.in);

        System.out.println("enter the value of a :");        

        int a = sc.nextInt();

        System.out.println("enter the value of b :");

        int b = sc.nextInt();

        System.out.println("the value and be is :\na = "+a+" and b = "+b+);       

        int temp;


        temp = a ;

        a = b;

        b = temp;

         System.out.println("the value a and b after the swappint is :\na = "+a+" and b = "+b);

     }

}

Post a Comment

0 Comments