Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Main {
  public static void main(String[] args) {
    int arr[] = new int[5];
    int c,x;
    int n = arr.length; 
    System.out.println("Original numbers: ");
    for(x = 0; x < 5; x++){
      arr[x] = (int) (30 * Math.random() + 1);
      System.out.print(arr[x] + " ");
    }

    for(c = 0; c< (x - 1); c++){
      for(int d = 0; d < x - c - 1; d++){
        if(arr[d] > arr[d+1]){
          int swap = arr[d];
          arr[d] = arr[d+1];
          arr[d+1] = swap;
          }
        }
      }
    System.out.println("");
    System.out.println("Sorted numbers: ");
    //c = remove(arr, n); 
    for(c = 0; c < 5; c++){
      System.out.print(arr[c] + " ");
    }
  }
}

/*
class remove
{ 
    // Function to remove duplicate elements 
    // This function returns new size of modified 
    // array. 
public static int remove(int arr[], int n) 
    { 
        // Return, if array is empty 
        // or contains a single element 
        if(n==0 || n==1){ 
            return n; 
        }
       
        int[] temp = new int[n]; 
          
        // Start traversing elements 
        int j = 0; 
        for(int i=0; i<n-1; i++){ 
            if(arr[i] != arr[i+1]){ 
                temp[j++] = arr[i]; 
            }
          }
        temp[j++] = arr[n-1];    
          
        // Modify original array 
        for(int i=0; i<j; i++){
            arr[i] = temp[i]; 
        }
        return j; 
    }

}
*/