| | |
Why Doesn't My Sort Work!?
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
WHAT IS WRONG HERE?WHY WON'T THIS SORT?
public class bubble
{
public static void main (String[] args)
{
boolean Finished;
int[] intRand = new int[11];
int[] unSorted = new int[11];
int intStore;
int i;
Finished = false;
i = 1;
while (i < 11)
{
intRand[i] = (int)(java.lang.Math.random() * 100);
unSorted[i] = intRand[i];
i = i + 1;
}
do
{
Finished = true;
for (i = 2; i < 11; ++i)
{
if (intRand[i] < intRand[i-1])
{
intStore = intRand[i];
intRand[i] = intRand[i-1];
intRand[i-1] = intStore;
Finished = false;
}
}
}
while (Finished==true );
System.out.println("Unsorted Sorted");
i = 1;
while (i < 11)
{
System.out.print(unSorted[i] + "\t"+ "\t");
System.ouWHATt.println(intRand[i]);
i = i + 1;
}
}
}
public class bubble
{
public static void main (String[] args)
{
boolean Finished;
int[] intRand = new int[11];
int[] unSorted = new int[11];
int intStore;
int i;
Finished = false;
i = 1;
while (i < 11)
{
intRand[i] = (int)(java.lang.Math.random() * 100);
unSorted[i] = intRand[i];
i = i + 1;
}
do
{
Finished = true;
for (i = 2; i < 11; ++i)
{
if (intRand[i] < intRand[i-1])
{
intStore = intRand[i];
intRand[i] = intRand[i-1];
intRand[i-1] = intStore;
Finished = false;
}
}
}
while (Finished==true );
System.out.println("Unsorted Sorted");
i = 1;
while (i < 11)
{
System.out.print(unSorted[i] + "\t"+ "\t");
System.ouWHATt.println(intRand[i]);
i = i + 1;
}
}
}
Java Syntax (Toggle Plain Text)
package untitled4; import java.util.*; public class bubble { public static void main (String[] args) { int[] intRand = new int[11]; int[] unSorted = new int[11]; int i; i = 1; while (i < 11) { intRand[i] = (int)(java.lang.Math.random() * 100); unSorted[i] = intRand[i]; i = i + 1; } Arrays.sort(intRand); System.out.println("Hello"); for(i = 0; i<intRand.length;) { System.out.print(unSorted[i] + "\t"+ "\t"); System.out.println(intRand[i]); i++; } } }
![]() |
Similar Threads
- radix sort (C++)
- bubble sort help (Python)
- Bubble Sort (C++)
- C++ Bubble sort not working with array of records, does work with simple array. (C++)
- descending bucket sort in 68000 (Assembly)
- questions on radix sort programs (C++)
- I can't sort out Insertion Sort! (C)
- Why won't my sort work?! (Java)
Other Threads in the Java Forum
- Previous Thread: loop to create arrays when reading a file
- Next Thread: getting a nullpointer exception
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character chat class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list loops mac map method methods mobile netbeans newbie notdisplaying number online printf problem program programming project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor





