Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] draw = new int[6];
- Scanner sc = new Scanner(System.in);
- int count = 0;
- int hatred = sc.nextInt();
- while(count < 6) {//抽取出六個數字放入陣列
- int rand = (int)(Math.random()*48+1);//設定抽取的數字範圍
- draw[count] = rand;
- if(((hatred == 0)&&(rand % 10 != 0))||((rand % 10 != hatred)&& (rand/10!=hatred))) {
- /*設定不討厭的數字的條件(討厭的數字為零而且rand除以10餘數不等於0)或是(討厭的數字不等於0時
- rand除以10的商數跟餘數不等於討厭的數字*/
- if(count==0) {//如果第一個數字符合就++
- count++;
- }
- else { //設定排除重複的條件
- for(int k = 0;k < count; k++ ) {
- if(draw[count]!= draw[k])
- continue;
- }
- count++;
- }
- }
- }
- for(int lucky = 0; lucky<6 ;lucky++) {
- System.out.print(draw[lucky]+" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement