Simple sort program wont work

Hi, i have to make a program to accept 15 numbers from a user into an array, then sort them in ascending order and print them.

I know how to code it, but for some reason after i compile and try to run this in BlueJ, it shows the program is being executed(Work indicator turns red), but nothing happens.

Ive re-written it several times, but no luck.

import java.io.*;

publicclass Worksheet5_2

{

publicvoid display()throws IOException

{

InputStreamReader isr =new InputStreamReader(System.in);

BufferedReader br =new BufferedReader(isr);

int arr[] =newint[15];

for (int i=0;i<arr.length;i++)

{

arr[i]=Integer.parseInt(br.readLine());

}

System.out.println("The numbers you entered are");

print(arr);

sort(arr);

System.out.println("\n Numbers in ascending order");

print(arr);

}

privatevoid sort(int arr[])

{

for (int i=0;i<arr.length-1;i++)

{

for (int j=i+1;j<arr.length;j++)

{

if (arr[i]>arr[j])

{

int temp = arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

}

}

privatevoid print(int arr[])

{

for (int i=0;i<arr.length;i++)

{

System.out.print(arr[i]+" ");

}

}

}

>

[2785 byte] By [Overkilla] at [2007-11-27 9:55:21]
# 1
Define "nothing happens."Put some diagnostic print statements in the program to narrow dow the problem.
ChuckBinga at 2007-7-13 0:25:18 > top of Java-index,Java Essentials,Java Programming...
# 2
NVM Its working now, though i cant figure out why :(In the starting statements where i initalize ISR and BR and take the input there was apparently some problem. I copied the exact same code for input from another program i made and it works now... weird
Overkilla at 2007-7-13 0:25:18 > top of Java-index,Java Essentials,Java Programming...
# 3

Here's a one-line way to sort your integers:

#

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class IntegerSort {

public static void main(String[] args) {

List<Integer> ints = new ArrayList<Integer>();

Integer i1 = new Integer(15);

Integer i2 = new Integer(5);

Integer i3 = new Integer(25);

Integer i4 = new Integer(12);

Integer i5 = new Integer(7);

ints.add(i1);

ints.add(i2);

ints.add(i3);

ints.add(i4);

ints.add(i5);

// one line sort

Collections.sort(ints);

for (Integer i : ints) {

System.out.println(i);

}

}

}

sleggea at 2007-7-13 0:25:18 > top of Java-index,Java Essentials,Java Programming...
# 4

As long as we are shrinking the code :-)

import java.util.Arrays;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class IntegerSort {

public static void main(String[] args) {

List<Integer> ints = new ArrayList<Integer>(Arrays.asList(15, 5, 25, 12, 7));

// one line sort

Collections.sort(ints);

System.out.println(ints);

}

}

BigDaddyLoveHandlesa at 2007-7-13 0:25:19 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks guys, but i havent learnt about Array Lists or Collections so i cant use them yet.
Overkilla at 2007-7-13 0:25:19 > top of Java-index,Java Essentials,Java Programming...