I want to sort it by not using Array sorting.

``````import java.util.Scanner;
public class practice5 {

public static void main(String[] args) {
Scanner p = new Scanner(System.in);
int i,j,temp = 0;
int min=0, max=0;
String w;

System.out.print("Enter a Number to sort:"); w = p.nextLine();

String[] m = w.split("\\s+");
int [] a = new int[m.length];

for ( i = 0; i<m.length; i++)
{
a[i] = Integer.parseInt(m[i]);

}

for(i=0; i<a.length-1; i ++){
for (j=0; j<a.length-i-1; j++){

if (a[j]>a[j+1])
{

temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;

}

}

}

for (i = 0; i<a.length;i++)System.out.print(a[i] + " ");

}
``````

It is sorting but i want to show the sorting by step by step proccess for example:
Number inputed is : 3 2 1
1st sort is : 2 3 1
2nd sort is : 2 1 3
Last sort is : 1 2 3
Thanks in advance :) i know there's a missing code in my code but i tried several things but i still can't get it

so .. at the end of each (outer-) for loop, add a print statement, printing the current order.

as I said: as last statement of that if-block, or as last statement of the outer loop, add a print statement that prints the current contents of the array

## All 6 Replies

so .. at the end of each (outer-) for loop, add a print statement, printing the current order.

how do i show the sorting part by step by step process. for example i input : 3 2 1 i like the output would be like this
1st sort : 2 3 1
2nd sort : 2 1 3
then the lat is : 1 2 3
am i making any sense? hehe just a newbie :)

as I said: as last statement of that if-block, or as last statement of the outer loop, add a print statement that prints the current contents of the array

Try adding print statements everywhere around the last statement and eventually you'll get wha you wanted.

thanks :D

if your sorting numbers , instead of the complicated looking stuff you did there , why not just use the nextInt() method of Scanner instead of nextLine() ? but if you want to stick to reading line and parsing it , better just use readLine() from BufferedReader and .split() the read line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.