Swap - reference parameters - Practice Exercises Java Lesson 5: Functions Exercise 5.10: Swap - reference parameters Objetive: Create a function named "Swap" to swap the values of two integer numbers, which are passed by reference. An example of use might be: int x=5, y=3; Swap(ref x, ref y); Console.WriteLine("x={0}, y={1}", x, y); (which should write "x=3, y=5") Source Code: JAVA C# public class Main { public static void Swap(int x, int y) { int swap; swap = x; x = y; y = swap; } public static static void main(String[] args) { int x = 5; int y = 3; Swap(x, y); System.out.printf("x: %1$s , y: %2$s" + "\r\n", x, y); } } Copy Exercise to ClipBoard Copy Code to ClipBoard Exercisey 5.10
More exercises for Lesson 5 Previous Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Next >>