Program Swapping Two Numbers In Java With 3rd Variable - HelpMeOutAlways

Saturday, February 23, 2019

Program Swapping Two Numbers In Java With 3rd Variable

Source Code

import java.util.Scanner;
 class InterchangeNo{
 
  public void swap(){
   int x, y, temp;
      System.out.println("Enter any two numbers for swaping them:");
      Scanner in = new Scanner(System.in);
   
      x = in.nextInt();
      y = in.nextInt();
   
      System.out.println("Before Swapping it was\nx = "+x+"\ny = "+y);
   
      temp = x;
      x = y;
      y = temp;
   
      System.out.println("After Swapping it is\nx = "+x+"\ny = "+y); 
  }
 }
class Main{
   public static void main(String args[]){
   InterchangeNo obj=new InterchangeNo();
   obj.swap();
   
   }
}

Output

java program

No comments:

@way2themes