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

VulpesRank #55 · 29.2K reputationPosted Jan 15, 2012, 12:49 PM EST
Prime bRank #2,035 · 712 reputationPosted Jan 15, 2012, 1:42 PM EST
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
VulpesRank #55 · 29.2K reputationPosted Jan 15, 2012, 2:04 PM EST
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 bRank #2,035 · 712 reputationPosted Jan 15, 2012, 2:08 PM EST