0

Sorting an array in ascending order

I want to do a code where: -Only accepts up to 50 integers -Sentinel value of 0 (zero) -Only accepts positive numbers (And ignores negative numbers) -Sorts the inputted numbers into ascending order. I use eclipse as my compiler. but when I run my code nothing appears. This is my code: https://code.sololearn.com/cxhIFj1f4J6Z

19th Sep 2021, 10:24 AM
Eka
Eka - avatar
5 odpowiedzi
+ 2
Martin Taylor Now you can check and tell me if still there is some issues, I have resolved all problem. My input example is like this: 3 -12 11 10 4 1 3 2 7 5 1 -2 3 4 5 0 //exit value
19th Sep 2021, 4:19 PM
A͢J
A͢J - avatar
+ 1
You algorithm for ordering of the array items do not work. A easier algorithm is to set „tem“ with the first array item and thing it is bigest. And then check another etc. You can see a few sorting algorithms samples here: https://www.sololearn.com/learn/774/
19th Sep 2021, 10:57 AM
JaScript
JaScript - avatar
+ 1
Eka 2 mistakes: 1 - You are closing scanner object 'input' inside loop which will give exception 2 - there should be temp = num[k] instead of temp = num[i] So here is solution, I have created different methods for different operations. https://code.sololearn.com/cTa6XLUuvIRu/?ref=app
19th Sep 2021, 11:59 AM
A͢J
A͢J - avatar
+ 1
Martin Taylor Can you tell me when it is coming because I had entered input like this: 3 //no of elements 4 5 6 0 //to break do while loop And it worked fine without any exception And worked well on this inputs too: 5 4 -13 3 2 1 -12 0
19th Sep 2021, 2:05 PM
A͢J
A͢J - avatar
+ 1
Martin Taylor Yes I got that exception when we enter less number of elements. Now please can you check?
19th Sep 2021, 2:46 PM
A͢J
A͢J - avatar