aspose file tools*
The moose likes Beginning Java and the fly likes Oh gosh, i think it's a BUG ?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Oh gosh, i think it Watch "Oh gosh, i think it New topic
Author

Oh gosh, i think it's a BUG ?!

Ken Ng
Greenhorn

Joined: Feb 14, 2004
Posts: 26
hi all, this post is a sequel to the message:
(anti)clockwise rotation of array elements...HELP!
Original intention of previous msg
int[] a = {1,2,3,4,5};
Rotate CLOCKWISE => 2,3,4,5,1
Rotate ANTI-CLOCKWISE => 5,1,2,3,4
--------------------------------------------------------------------------
I had posted my code for this problem. If u were to try vicken's modified version of my code(which is more readable and efficient, My (ken's) code got some error for ANTI-CLOCKWISE)
1) Inside main(),

You get,
5 1 2 3 4 (ANTI-CLOCKWISE result)
1 2 3 4 5 (CLOCKWISE result)

2) Now, modify inside main() by just interchanging the clockwise() and antiClockwise() statement,

You get
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)

3) Next, modify accordingly inside main() to do continous rotation

you get
Initially...1 2 3 4 5
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)

4) Lastly (hope u are still with me) to get around this problem, modify again,

You get,
Initially...1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
1 2 3 4 5
Initially...1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2
2 3 4 5 1
1 2 3 4 5
--------------------------------------------------------------------
These Demo shows 3 things.
-Both ANTI-CLOCKWISE and CLOCKWISE algorithm works!
-ANTI-CLOCKWISE works but CLOCKWISE fails and vice versa if used one after the other
-U see that 5 rotations were performed continously w/o problem for ANTICLOCKWISE case and CLOCKWISE case SEPARATELY.

CONCLUSION!
YOU CAN'T DO AN ANTI-CLOCKWISE ROTATION OF AN ARRAY BEFORE OR AFTER A CLOCKWISE ROTATION !!!
BUT YOU COULD PERFORM ONE AND ONLY ONE TYPE OF ROTATION CONTINOUSLY W/O PROBLEM

Someone PLS tell me it's not a bug and explain it.
[ March 15, 2004: Message edited by: Ken Ng ]
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
I have read your post three times already, and couldn�t see anything extraordinary about the code. The code is working fine as expected, there is no error, no bugs�. Nothing.
One thing you should know is that arrays are object in java; if you do a clockwise/ anticlockwise rotation you are actually changing the order of the elements in the array. You can�t expect the array remains the same after performing any of these rotations.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Ravi Srinivas
Greenhorn

Joined: Sep 04, 2003
Posts: 26
I havent seen your earlier post, but based on this one it does seem as if there is no bug. If you take an array, rotate it anti-clockwise once and then rotate it clockwise once you will end up with the original array.
This is also what your code shows, so I guess there is no bug.
When you said that rotating clockwise and anti-clockwise alternately doesnt work, did you expect the original array as a result or something else?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oh gosh, i think it's a BUG ?!
 
Similar Threads
Need help on print , scrollbar for my applet
Stopping Animation
Loops
(anti)clockwise rotation of array elements...HELP!
Code to print , rotate, zoom an image from an applet