Monday 23 March 2020

EXCHANGE VALUE USING JAVA LANGUAGE

Q-8-Write a java program to exchange the values of two variables of integer type A and B without using third temporary variable.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=10;
int b=20;
a=a+b;
b=a-b;
a=a-b;
System.out.println(a);
System.out.println(b);
}

}

OUTPUT :
20

10

No comments:

Post a Comment