Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaarray.arraytest;
- import java.util.Random;
- /**
- *
- * @author xrener
- */
- public class TestArray
- {
- private static void bubbleSort(int arr[])
- {
- int n = arr.length;
- for (int i = 0; i < n-1; i++)
- for (int j = 0; j < n-i-1; j++)
- if (arr[j] > arr[j+1])
- {
- // swap temp and arr[i]
- int temp = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = temp;
- }
- }
- public static void arrayInit()
- {
- int[] MyArray = new int[32];
- System.out.println("Dlzka mojho pola: "+ MyArray.length +"");
- Random rand = new Random();
- for(int i = 0; i < MyArray.length; i++)
- {
- MyArray[i] = rand.nextInt(32);
- System.out.println("Nahodna hodnota: "+ MyArray[i] +"");
- }
- bubbleSort(MyArray);
- for(int i = 0; i < MyArray.length; i++)
- {
- System.out.println("Sortovane hodnoty: "+ MyArray[i] +"");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment