Java implementation code of the "two-color ball" lottery Algorithm for China Welfare Lottery

Source: Internet
Author: User

 

Code:
  1. Import java. Io. ioexception;
  2. Import java. util .*;
  3. Public class doubleball {
  4. Private int N [] = new int [6];
  5. Private random r = new random ();
  6. Public int [] doublebal (){
  7. Int I = 0;
  8. While (I <n. Length ){
  9. N [I] = R. nextint (33) + 1;
  10. If (compared (n, I, n [I]) {
  11. I ++;
  12. }
  13. }
  14. Return N;
  15. }
  16. Public Boolean compared (int n [], int index, int d ){
  17. Boolean flag = true;
  18. For (INT I = 0; I <index; I ++ ){
  19. If (N [I] = d ){
  20. Flag = false;
  21. }
  22. }
  23. Return flag;
  24. }
  25. Public void sortarray (int n []) {
  26. For (INT I = 0; I <n. length; I ++ ){
  27. Int temp;
  28. For (Int J = 0; j <n. length-i-1; j ++ ){
  29. If (N [J]> N [J + 1]) {
  30. Temp = N [J];
  31. N [J] = N [J + 1];
  32. N [J + 1] = temp;
  33. }
  34. }
  35. }
  36. }
  37. Public void printnums (int n ){
  38. For (int K = 0; k <n; k ++ ){
  39. Int [] n1 = doublebal ();
  40. Sortarray (N1 );
  41. System. Out. Print ("red ball :");
  42. For (INT I = 0; I <6; I ++ ){
  43. System. Out. Print ("/t" + add0 (N1 [I]);
  44. }
  45. System. Out. Print ("/T Blue ball:" + add0 (R. nextint (16) + 1) + "/N ");
  46. }
  47. }
  48. Public String add0 (int n ){
  49. String STR = "";
  50. If (n <10 ){
  51. STR = "0" + N;
  52. } Else {
  53. STR = N + "";
  54. }
  55. Return STR;
  56. }
  57. Public static void main (string ARGs []) {
  58. Doubleball DB = new doubleball ();
  59. DB. printnums (5 );
  60. }
  61. }

Run this program to generate a five-color two-color ball number. By modifying the parameters in db. printnums ();, you can control the number of bets generated. This code is for your reference only. If you use the resulting number as the bet code, the author shall not be liable for any consequences!
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.