Hi everyone. I am currently taking a beginners course in java programming at the university of Aarhus. We are now 2 weeks in to the course and our teacher has suggested that we should start some small projects to work on, on our own. So i have decided to try and write a bubblesort algorithm.
Now i havenīt really gotten very far yet but i am getting a failure-message called
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at bubbleSort.main(bubbleSort.java:20)"
I basically do not understand why i am getting it. I hope that someone can explain it to me. And please keep in mind that you may have to "dumb it down" for me since i am only 2 weeks in to the course. I have already tried to look it up here ArrayIndexOutOfBoundsException (Java 2 Platform SE v1.4.2) and i still don't get it.
import java.util.Vector; public class bubbleSort { public static void main(String[] args) { String[] name={"Thor", "Jensen", "Soeren"}; Vector v = new Vector(); int zero=0; int one=1; int runTimes = name.length; while(runTimes>0){ if(name[zero].length() >= name[one].length()){ v.insertElementAt(name[zero], 0); zero++; one++; runTimes--; } else { v.insertElementAt(name[one], 0); zero++; one++; runTimes--; } } System.out.println(v); } }