8:17 pm - Thursday April 25, 2019

Java program using Swapping

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 Swapping

{

//declare the method as static

static void swap(int i,int j)

{

int temp=i;

//Interchanging the values of i and j  using temp variable

i=j;

j=temp;

//Display the values  after   Swapping

System.out.println("After swapping i = " + i + " j = " + j);

}

public static void main(String[] args)

{

int i=5;

int j=10;

//Display the values before  Swapping

System.out.println("Before swapping i="+i+" j="+j);

//access static method using class name without  creating objects

Swapping.swap(i,j);

}

}

Output:

D:\Candidjava\Code>javac Swapping.java

D:\ Candidjava\Code >java Swapping

Before swapping i=5 j=10

After swapping i = 10 j = 5

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply