Advertisement
apa6143171

Untitled

Dec 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. int[] draw = new int[6];
  2. Scanner sc = new Scanner(System.in);
  3. int count = 0;
  4. int hatred = sc.nextInt();
  5. while(count < 6) {//抽取出六個數字放入陣列
  6. int rand = (int)(Math.random()*48+1);//設定抽取的數字範圍
  7. draw[count] = rand;
  8. if(((hatred == 0)&&(rand % 10 != 0))||((rand % 10 != hatred)&& (rand/10!=hatred))) {
  9. /*設定不討厭的數字的條件(討厭的數字為零而且rand除以10餘數不等於0)或是(討厭的數字不等於0時
  10. rand除以10的商數跟餘數不等於討厭的數字*/
  11. if(count==0) {//如果第一個數字符合就++
  12. count++;
  13. }
  14. else { //設定排除重複的條件
  15. for(int k = 0;k < count; k++ ) {
  16. if(draw[count]!= draw[k])
  17. continue;
  18. }
  19. count++;
  20. }
  21. }
  22. }
  23. for(int lucky = 0; lucky<6 ;lucky++) {
  24. System.out.print(draw[lucky]+" ");
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement