Brett Brett - 1 year ago 184
Java Question

Sort array from smallest to largest using java

I'm supposed to create an array and sort the numbers from smallest to largest. Here is what I have so far:

public class bubbleSort {

public static void sort (int [] arrayName){
int temp;
for (int i = 0; i < arrayName.length-1; i++)
if(arrayName[i] > arrayName[i+1])

public static void main(String[] args) {
int [] arrayName = new int[10];
for (int i = 0; i < arrayName.length; i++) {
arrayName[i] = (int)(Math.random()*100);


I am getting an error on the last line where I'm trying to print it out. What am I doing wrong?

Answer Source

Your sort(int[] array) method returns nothing. It is void, therefore you cannot print its return.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download