Wednesday, September 1, 2010

JAVA Sort

import java.util.*;
public class Example 
{
 public static void main (String[] args) 
 {
  Random number = new Random();
  
  // Generate 5 randoms numbers from 1 to 100
  int number1 = number.nextInt(100);
  int number2 = number.nextInt(100);
  int number3 = number.nextInt(100);
  int number4 = number.nextInt(100);
  int number5 = number.nextInt(100);

  int[] numbers = new int[] {number1, number2, number3, number4, number5};
  Arrays.sort(numbers);
  System.out.println(Arrays.toString(numbers));
 }
}

1 comment:

  1. Great!. This is what I call resourcefulness.
    Why do something if it already exists!
    You get full points.

    However, it would still be desirable to know how sorting is done.
    Can you write a new member function say, "mysort" which will sort the numbers, and generate the same output at this sorting function.

    -Aviral

    ReplyDelete