fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] array= {3, 9, 2};
  13. intsertionSort(array);
  14. }
  15. public static void intsertionSort(int[] arr){
  16. for (int i=1; i<arr.length;i++){
  17. int valueToInsert =arr[i];
  18. int j;
  19. //below this is error point in your code
  20. for(j=i-1;j>=0 && valueToInsert <arr[j];j--)
  21. arr[j+1]=arr[j];
  22. arr[j+1]=valueToInsert;
  23. }
  24. //used for testing the function
  25. for(int a:arr){
  26. System.out.println(a);
  27. }
  28. }
  29. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
2
3
9