Sorting an array with Arrays.sort method - Java Language Basics

Java examples for Language Basics:Array

Description

Sorting an array with Arrays.sort method

Demo Code

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    int[] lotto = new int[6];

    for (int i = 0; i < 6; i++)
      lotto[i] = (int) (Math.random() * 100) + 1;
    /* ww  w  . j  a v  a 2s .c  o m*/
    System.out.println(Arrays.toString(lotto));
    Arrays.sort(lotto);
    System.out.println(Arrays.toString(lotto));
  }

}

Related Tutorials