aspose file tools*
The moose likes Beginning Java and the fly likes Please help me... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help me..." Watch "Please help me..." New topic
Author

Please help me...

Chaturaka Gunatilaka
Greenhorn

Joined: Oct 06, 2012
Posts: 16
Here is the code.



Whats wrong with this?Thank you.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Chaturaka Gunatilaka wrote:Whats wrong with this?Thank you.

What makes you think there is something wrong with it ? TellTheDetails
Chaturaka Gunatilaka
Greenhorn

Joined: Oct 06, 2012
Posts: 16
Stuart A. Burkett wrote:
Chaturaka Gunatilaka wrote:Whats wrong with this?Thank you.

What makes you think there is something wrong with it ? TellTheDetails


There is an out of bound exception.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Chaturaka Gunatilaka wrote:There is an out of bound exception.

Where ? TellTheDetails - read this link carefully before posting again.
Chaturaka Gunatilaka
Greenhorn

Joined: Oct 06, 2012
Posts: 16
Error

Sorted values :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at sort.partition(sort.java:11)
at quickSort.main(quickSort.java:6)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Also, please UseAMeaningfulSubjectLine instead of "Please help me" when you post a question.

ArrayIndexOutOfBoundsException means that you're trying to access an array using an invalid index. If the length of the array is N, then 0 upto and including N - 1 are valid indices.

Read the error message carefully. It tells you exactly in which line the error occurs. Carefully analyze your program to see what happens. Add some System.out.println(...) statements to print out useful information, to help you understand what's happening. You could also run the code using a debugger, so that you can step through the code line by line while it runs, which might help you understand what happens exactly.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

One more point... The partition(...) method should be used internally by method that actually implements the algorithm (if you really want Quicksort) and not invoked separately from main. So I would make that one private and change the implementation accordingly.


The quieter you are, the more you are able to hear.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

you can always stick in System.out.println() statements to see what your code is doing. Whichever line is throwing the error, print out what index you are trying to reference. You will probably see you are trying to access index n on an array that has n elements. Since you can only use indexes 0 through n - 1, using n give an out of bounds exception.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
jQuery in Action, 2nd edition
 
subject: Please help me...
 
Similar Threads
Need help figuring out a quickSort problem
StackOverflow error using QuickSort
Comparing values
Parallel running quicksort
Overwriting an array.