I am afraid I don't think that code can be rescued. I think you will have to start again.
Start with a class to encapsulate your calculations. Then another class with a proper
main method, 1 statement long:-
I see you have indented your code, but it isn't consistent; line 6 ought to be a little to the right of line 5, for example. Incorrect indentation can cause confusing errors. I have my own suggestions about how to do indenting, which I showed
here.
Give your variables names which mean something. You will read this code in three weeks and not know what aS means. And why are you using double arithmetic when all those numbers are integers? Use int arithmetic for whole numbers.
Never use doubles in loop variables. Always use integers. You can get subtle tiny errors with double arithmetic which will cause your loop to behave incorrectly.
Never write == false or == true. That is poor style and error‑prone. What if you write = by mistake?
Never
if (b == true) ...
Always
if (b) ...
Never
if (b == false) ...
Always
if (!b) ...
That method (as you will have read from the link) is much too long. You need separate methods which sort arrays. In fact I think you need a separate class. I wrote about that last week, so look in
this thread for how to do it. If you write a simple bubble sort method, it will be shorter than your lines 50-75. I haven't read that code in detail, but seeing things like
length + 1 and
length * 2 worry me; I think you will go beyond the bounds of an array and suffer an Exception.