java - How do I print a sorted array? -


this question has answer here:

the following code supposed sort array initialized below.

int[] intarray = { 32, 42, 1, 23, 56, 75, 32, 23 }; int temp = 0;  (int = 0; < intarray.length; i++) {   (int j = 1; j < intarray.length; j++) {     if (intarray[j - 1] > intarray[j]) {       temp = intarray[j - 1];       intarray[j - 1] = intarray[j];       intarray[j] = temp;     }   } } 

what should type sorted array , should type it?

i have tried options such system.out.println(temp) between last 2 closing brackets , 1 before those, not getting values printed, , 32 printing many times instead.

writing code system.out.println(j) or system.out.println(i) in same area doesn't work either. can explain why these codes don't work?

if want print sorted array, print elements in loop after array sorted:

for(int i=0; < intarray.length; i++) {     system.out.println(intarray[i]); } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -