<pre><code><strong>public class Sort {</strong>
<strong>
public static void main(String[] strr) {</strong>
<strong>
int arr[] = {9,8,7,6,5,4,3,2,1};</strong>
<strong>
System.out.println(" Before sorting");</strong>
<strong>
for(int j=0;j<;=arr.length-1;j++)</strong>
<strong>
{</strong>
<strong>
System.out.print(" "+arr[j]);</strong>
<strong>
}</strong>
<strong>
new Sort().insertionSort(arr);</strong>
<strong>
System.out.println("\nAfter Sorting");</strong>
<strong>
for(int j=0;j<;=arr.length-1;j++)</strong>
<strong>
{</strong>
<strong>
System.out.print(" "+arr[j]);</strong>
<strong>
}</strong>
<strong>
}</strong>
<strong>
public void insertionSort(int arr[]) {</strong>
<strong>
int temp;</strong>
<strong>
for(int i=1;i<;=arr.length-1;i++) {</strong>
<strong>
temp=arr[i];</strong>
<strong>
int j;</strong>
<strong>
for (j=i-1; j>;=0; j-- ) {</strong>
<strong>
if(arr[j]>;temp)</strong>
<strong>
arr[j+1]=arr[j];</strong>
<strong>
}</strong>
<strong>
arr[j+1]=temp;</strong>
<strong>
}</strong>
<strong>
}</strong>
<strong>
}</strong>
</code></pre>
<h4><span style="color: #000080;"><strong>Output:</strong></span></h4>
<p><strong><span style="color: #0000ff;">Before sorting</span></strong><br />
<strong><span style="color: #0000ff;">9 8 7 6 5 4 3 2 1</span></strong><br />
<strong><span style="color: #0000ff;">After Sorting</span></strong><br />
<strong><span style="color: #0000ff;">1 2 3 4 5 6 7 8 9</span></strong></p>


