Create a new program named Reverse4, which contains
a method that reverses the positions of four variables.
Write a Main() method that demonstrates the method
works correctly.
its should be something like
int temp;
temp = first;
first = second;
second = third;
etc, i donno how to solve it
Loading
VulpesPosted Jan 15, 2012, 5:49 PM
Prime bPosted Jan 15, 2012, 7:08 PM
VulpesPosted Jan 15, 2012, 7:04 PM
You can, of course, only swap two variables at a time and you need to use a temporary variable to hold one variable before it is overwritten by the other.
The 'ref' parameters ensure that the swapped variables will be persisted to the calling method.
Prime bPosted Jan 15, 2012, 6:42 PM
In main method i had
111
222
333
444
and in reverse method i did it like that
int temp;
temp = first;
first = fourth;
fourth = third;
third = second;
second = temp;
The output would be 111,222,333,444
and then 444,111,222,333