2013-02-21 3 views
-2

다음 코드에 대해 무작위로 생성 된 정수 배열을 정렬 (오름차순) 할 수 있습니까? 그렇다면 어떻게?무작위 배열 정렬

import java.util.Random;

공용 클래스 RandomArraySorter {

 public static void main(String args[]){ 
     Random random = new Random(); 

     int array[] = new int[10]; 

     //number of integer spaces within the array: 
     for(int i = 0; i < 10; i++){ 

     //random numbers from 1 to 100: 
     array[i] = random.nextInt(100) + 1; 

      System.out.print(array[i] + " "); 
     } 
    } //end of main 
} //end of class 

답변

2

당신은으로 정렬 할 수 있습니다

Arrays.sort(array);