Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class insertion {
  4. public static int arraySize = 10;
  5. public static int array[] = new int[10];
  6. public static Random rand = new Random();
  7.  
  8.  
  9. public static void pause(int time)
  10. {
  11. try
  12. {
  13. Thread.sleep(time);
  14. }
  15. catch(InterruptedException ex)
  16. {
  17. Thread.currentThread().interrupt();
  18. }
  19. }
  20.  
  21.  
  22. public static void main(String args[]){
  23. for(int i = 0; i<arraySize; i++){
  24. array[i]=rand.nextInt(10);
  25. System.out.println(array[i]);
  26. }
  27.  
  28. while(true){
  29. for(int i = arraySize-1; i>0;i--){
  30. System.out.println("Inside main for");
  31. pause(1500);
  32. if(array[i]<array[i-1]){
  33. for(int o=arraySize; o>0; o--){
  34. pause(1500);
  35. System.out.println("Inside second for");
  36. if(array[i]<=array[o]){
  37. System.out.println("If is being evaluated");
  38. int temp = array[i];
  39. array[i] = array[o];
  40. array[o] = temp;
  41. break;
  42. }
  43. if(o==1){
  44. pause(1500);
  45. System.out.println("Second if");
  46. int temp = array[i];
  47. array[i] = array[o];
  48. array[o] = temp;
  49. break;
  50. }
  51.  
  52.  
  53. }
  54.  
  55. }
  56. else{
  57. break;
  58. }
  59.  
  60. }
  61. break;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement