I have a few suggestions for you:
1) It would be advisable to use the .length attribute of the array object. So instead of for(i=0;i<10;i++) please uses for (i=0; i < ns.length; i++) Btw, why do you suppose we have access to the.length attribute of the array object? 'Cause it's declared final :icon_wink:
2) Another useful class to use when dealing with a text file is the Scanner class from the java.util package. With this class you can actually read-in the numbers as an int (which you can do anyway, but not this easily). But of course you don't need that, but I do feel in makes reading text from a file real simple :icon_idea:
3) Let's take a look at you're selection sort, it's a bit flawed (but no enough so for your program to not work). You should have:
for (i = 0; i < ns.length - 1; i++)
for (j = i + 1; j < ns.length; j++) Of course in this casens.length has a value of 11 so you'd need 10 in the outer-loop instead of 11. Why do we not access the last element in the outer-loop? Because the last element would have found its correct place when the second-last element was sorted. You should check out Wikipedia for more information :icon_cool:
4) You should not be creating a new instance of your class (i.e. don't use Score s=new Score(); ) just to gain access to thecodeDecode method. You'd simply call the static method from the class: String newScore = Score.codeDecode(score); This is the purpose of creating astatic method :icon_smile:
I'm actually not really sure why you're program isn't working hey :icon_confused: I can't really spend too much time looking at your code but I think you should look at the contents of the array after you're read the data from the file and the contents of the array after you sort - by simply displaying it:
for(String element: ns)
System.out.println(element); or
for (i = 0; i < ns.length; i++)
System.out.println(ns[i]); both have the same effect :icon_biggrin: Hope you find the bug!