LAB - 랜덤 함수 추출 및 저장 SourceCode

CODEDRAGON Development/Java

반응형


 

 

LAB - 랜덤 함수 추출 저장

http://codedragon.tistory.com/7977

 

 

 

SourceCode

package com.mathex;

 

import java.util.Arrays;

 

public class RandomEx07 {

 

public static void main(String[] args) {

// 크기가 20 배열 생성

int[] random = new int[20];

 

// 20 반복 수행하면 랜덤한 수를 배열에 저장

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

// 1~99 나올 수있도록 99곱한 1 더한 합으로 난수 생성

int n = (int) (Math.random()*99)+1;

// 배열에 저장

random[i] = n;

}

 

//배열 정렬

Arrays.sort(random);

 

System.out.println(Arrays.toString(random));

// [8, 13, 18, 19, 28, 30, 34, 34, 39, 57, 60, 62, 65, 66, 73, 90, 91, 92, 97, 98]

 

}

}

 

 

 


반응형