Ask your own question, for FREE!
Mathematics 44 Online
OpenStudy (yumi):

can anyone help me fix my code please?? JAVA

OpenStudy (mathmale):

You might get faster results if y ou'd post the JAVA code with which you want help. Explain why it needs "fixing."

OpenStudy (mathmale):

No, or I would have offered to help. Sorry.

OpenStudy (retireed):

I got my JaveScript version of the bubble sort to work.

OpenStudy (yumi):

thats my code

OpenStudy (yumi):

i need help getting the bubble sort in its own method rather than under the main method

OpenStudy (yumi):

and also, is there a way to get the ouput(numbers) to print in one single line, rather than individually?

OpenStudy (yumi):

can anyone help?

OpenStudy (retireed):

Sorry, I was fixing up my code. I don't understand this question: i need help getting the bubble sort in its own method rather than under the main method your second question: and also, is there a way to get the ouput(numbers) to print in one single line, rather than individually? my JS code does print in a single line, so I need to go through your code in order to understand the difference.

OpenStudy (yumi):

i mean, the bubble sort code should be in its own method. i have it under main method. how do i get it on its own rather than calling it from main?

OpenStudy (retireed):

Oh I see... you need to create a subroutine "ascendingBubble" you want the bubble sort to be a subroutine that you call from the main, so you don't have to rewrite the sort program every time, if it were to be requested several times. That would take more researching, since I don't recall that aspect of programming coming up in my JS course.

OpenStudy (retireed):

As for printing your sorted output on one line.... it looks to me that you are printing your output inside of a loop is the reason why you are getting separate lines. I would try to change your code.... System.out.println("sorted list is: "); to System.out.println("sorted list is: " +a);

OpenStudy (retireed):

My dog needs his walk, so I will be off for about an hour or two. Creating your subroutine should be easy for you to add to the bottom of or outside of your Main program.

OpenStudy (518nad):

retired ya theres a few mistakes in ur early code

OpenStudy (retireed):

I just ran my code a couple of times more and my random number generator, generated a zero. It looks like you used a similar code for your generator, so a fix is in order. something like Math.random()*99 + 1 Leaving now!

OpenStudy (518nad):

Hi I want to improve your algorithm

OpenStudy (518nad):

in a bubble sort after one check of the complete list, you will have the highest value on the right most side, so that is already sorted, in the next pass through the list, you only need to check the list to the left of the rightmost number, in the pass after than you have to check the whole list, excluding the 2 right most

OpenStudy (518nad):

|dw:1479575199085:dw|

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
happyday09: I drew this in a psych ward, lmk what u think
52 minutes ago 3 Replies 2 Medals
0bubz0: what should I do to my new JDM?
1 hour ago 2 Replies 0 Medals
Z1ah: Math
3 hours ago 8 Replies 1 Medal
JesusReyes: my life summed up
11 minutes ago 13 Replies 1 Medal
Redfox123: what is acid made out of
4 hours ago 7 Replies 6 Medals
Redfox123: what cam first the color orange or the orange itself????
4 hours ago 4 Replies 0 Medals
Redfox123: what is acid made out of
6 hours ago 0 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!