3:50 pm - Friday February 19, 7588

Java program for Swapping using third variable

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**

*@author :CandidJava.com

*@descriptions : This program explain the swaping method using third variable

*/

class Swap   {

public static void main(String[] args)  {

//Declaring   the values of x & y

int x=10,y=20;

//Display the values of x&y before swapping

 

System.out.println("Initial value: "+ x +" and " + y);

int z = x;

//interchanging the values of x and y using third variable z

x = y;

y = z;

//display the values of x and y after swaping

System.out.println("Swapped value: " + x +" and " + y);

}

}

Output:

D:\ Candidjava\Code >javac Swap.java

D:\ Candidjava\Code >java Swap

Initial value: 10 and 20

Swapped value: 20 and 10

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply