How to swap two numbers using function Java

1 Answer

0 votes
public class MyClass {
    public static int swap(int a, int b) {
        return a;
    }

    public static void main(String args[]) {
        int a = 7, b = 9;

        a = swap(b, b = a);
        System.out.println(a + " " + b);
    }
}



/*

9 7

*/

 



answered Apr 30, 2019 by avibootz

Related questions

1 answer 262 views
1 answer 683 views
1 answer 267 views
1 answer 277 views
277 views asked Apr 30, 2019 by avibootz
1 answer 280 views
1 answer 228 views
...