This code was made in five minutes, so there are many weak point.
this code save that the number from 1 to 45 has been count N times.
finally, i will get 6 numbers.
import java.util.Random;
public class lottonamatja {
public static void main(String[] args) {
Random ranNum = new Random(); // random variable
long[] cloneNum = new long[45];
long[] num = new long[45];
long[] lottoNum = new long[6]; // get real number(I wanted)
long count = 1;
long N = 100000000;
for (long i = 0; i< N ; i++) {
int tempRanNum = ranNum.nextInt(45)+1; // random number of 1~45
num[tempRanNum-1] += count; // count of each number about N times
}
//copy number
cloneNum = num.clone();
// sorting count
for (int i = 0; i < 45; i++) {
for (int j = i + 1; j < 45; j++) {
if (num[i] > num[j]) {
long tmp = 0;
tmp = num[i];
num[i] = num[j];
num[j] = tmp;
}
}
}
// compare sorting number to original number ( this is real number(1~45), num[i] or cloneNum[j] is counting number)
for (int i = 0 ; i < 6; i++) {
for (int j = 0 ; j < 45; j++) {
if (num[i] == cloneNum[j])
lottoNum[i] = j+1; // save result number
}
}
// sorting about 6 number
for (int i = 0; i < 6; i++) {
for (int j = i + 1; j < 6; j++) {
if (lottoNum[i] > lottoNum[j]) {
long tmp = 0;
tmp = lottoNum[i];
lottoNum[i] = lottoNum[j];
lottoNum[j] = tmp;
}
}
System.out.print(lottoNum[i] + " "); //i wanted to real number
}
}
}
Subscribe to:
Post Comments (Atom)
알뜰폰 삼성페이 교통카드 '한도 초과' 오류(등록 불가 오류) 해결방법
sk7mobile 알뜰폰 삼성페이 교통카드 등록 시, 한도 초과 문제 해결방법 skt usim 해킹 사건으로 인해 sk7mobile 알뜰폰을 사용하는 저도 usim을 바꾸고 나니 삼성페이 교통카드가 등록이 안되더라구요... 삼성페이 교통카드 기능 은...
-
How to Start a Career in Renewable Energy: Best Jobs, Skills & Training for a Green Future 🌱⚡ Why the Renewable Energy Industry Is th...
-
Choosing Pet Insurance in New York (2024): Benefits and Cost Comparison 🐾 Owning a pet in New York City comes with countless joys, but al...
-
How to install Linux(Ubuntu) in Windows10 1. Enter "Setting" (Right-click the Windows logo at the bottom left.) ...
No comments:
Post a Comment