Presuming you type the code into your post and you missed the space between 'private' and 'void', and presuming that the first and last close squiggly brackets are properly paired with another block of code (above) and the end of the class (below), then the code should work and the problem may be at a more general level.
You should be more specific as far as the issue in your posts. Saying 'why can't i make it work' if very vague. How is it not working (what results are you getting)? How should it work (what results should you be getting -- here, it is quite obvious with the code itself)? Show any related code that might be of assistance in helping you (often this includes where the method is called from; what class and type of class the method is in; etc.).