Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,931 questions

51,868 answers

573 users

How to swap two numbers in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        int n1 = 12, n2 = 98;
 
        int temp = n1;
        n1 = n2;
        n2 = temp;
 
        System.out.println("n1 = " + n1);
        System.out.println("n2 = " + n2);
    }
}



/*
run:

n1 = 98
n2 = 12

*/

 



answered Jan 11, 2022 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        int a = 12, b = 98;
  
        b = a + b;
        a = b - a;
        b = b - a;
  
        System.out.println("a = " + a);
        System.out.println("b = " + b);
    }
}
 
 
 
/*
run:
 
a = 98
b = 12
 
*/

 



answered Jan 11, 2022 by avibootz

Related questions

1 answer 147 views
1 answer 170 views
1 answer 156 views
4 answers 248 views
1 answer 129 views
1 answer 99 views
1 answer 79 views
79 views asked Mar 19, 2023 by avibootz
...