A simple Java challenge. This really stumped me the first time I ran across it. I made it work but looking at the code made absolutley no sense. Give it a try and let me know how you do.
Consider the following values:
8 1 3
4 0 2
7 6 5
- Store the values in a two-dimensional array of int.
- Move the 0 up by modifying a single index and swapping two values.
- Print the result.
8 0 3
4 1 2
7 6 5
Rules.
- You may only use Java.
- You may only use a single array of type int[][].
- All intermediate variables must be int.
- You may only use the operators +, -, =, ++, --, or ==.
- You may not use any libraries other that System.out to print a result.
Question. Did you get it the first try?
Hint. There is an important distinction between values of a 2D array and cartesian space.