I'm working on a Bubblesort that's supposed to take a random array of numbers and return them but I keep getting a 'possible loss of precision' error when compiling that tells me Math.random is returning a double and I need an integer. How can I covert this?
public class Bubblesort {
public static void main(String[] args) {
//create an int array we want to sort using bubble sort algorithm
int intArray[] = new int [Math.random()*100];
Here's my code just in case.
Edit: There was more code involved that I didn't think I would need to include. I tried casting but System.out.println isn't working now.
Rest of the code:
public static void main(String[] args) {
//create an int array we want to sort using bubble sort algorithm
int intArray[] = new int [(int)Math.random()*100];
//int intArray[] = new int [100];
//print array before sorting using bubble sort algorithm
System.out.println("Array Before Bubble Sort");
for(int i=0; i < intArray.length; i++){
System.out.print(intArray[i] + " ");
}
//sort an array using bubble sort algorithm
bubbleSort(intArray);
System.out.println("");
//print array after sorting using bubble sort algorithm
System.out.println("Array After Bubble Sort");
for(int i=0; i < intArray.length; i++){
System.out.print(intArray[i] + " ");
}