1 package com.lixu.caipiao; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.widget.Button; 8 import android.widget.EditText; 9 10 public class MainActivity extends Activity implements OnClickListener { 11 Button btn1; 12 Button btn2; 13 Button btn3; 14 EditText et1; 15 EditText et2; 16 EditText et3; 17 StringBuffer sb; 18 StringBuffer sb2; 19 StringBuffer sb3; 20 21 @Override 22 protected void onCreate(Bundle savedInstanceState) { 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.activity_main); 25 26 btn1 = (Button) findViewById(R.id.btn1); 27 btn2 = (Button) findViewById(R.id.btn2); 28 btn3 = (Button) findViewById(R.id.btn3); 29 et1 = (EditText) findViewById(R.id.et1); 30 et2 = (EditText) findViewById(R.id.et2); 31 et3 = (EditText) findViewById(R.id.et3); 32 btn1.setOnClickListener(this); 33 btn2.setOnClickListener(this); 34 btn3.setOnClickListener(this); 35 } 36 37 @Override 38 public void onClick(View v) { 39 switch (v.getId()) { 40 case R.id.btn1: 41 sb = new StringBuffer(); 42 shuang(); 43 et1.setText(sb); 44 break; 45 case R.id.btn2: 46 sb2 = new StringBuffer(); 47 daletou(); 48 et2.setText(sb2); 49 break; 50 case R.id.btn3: 51 sb3 = new StringBuffer(); 52 qixing(); 53 et3.setText(sb3); 54 break; 55 56 default: 57 break; 58 } 59 60 } 61 62 public void shuang() { 63 int[] a = new int[7]; 64 int i = 0; 65 while (i < 6) { 66 int b = (int) (Math.random() * 33) + 1; 67 boolean temp = true; 68 for (int m = 0; m < a.length - 1; m++) { 69 if (a[m] == b) { 70 temp = false; 71 } 72 } 73 74 if (!temp) { 75 continue; 76 } 77 a[i] = b; 78 i++; 79 } 80 for (int l = 0; l < a.length - 1; l++) { 81 for (int h = 0; h < a.length - 1; h++) { 82 if (a[l] < a[h]) { 83 int temp = a[l]; 84 a[l] = a[h]; 85 a[h] = temp; 86 } 87 } 88 } 89 int k = (int) (Math.random() * 16) + 1; 90 a[6] = k; 91 for (int n : a) { 92 sb.append(n + ","); 93 } 94 } 95 96 public void daletou() { 97 int[] a = new int[7]; 98 int i = 0; 99 while (i < 5) { 100 int b = (int) (Math.random() * 35) + 1; 101 boolean temp = true; 102 for (int e = 0; e < a.length - 2; e++) { 103 if (a[e] == b) { 104 temp = false; 105 } 106 } 107 if (!temp) { 108 continue; 109 } 110 a[i] = b; 111 i++; 112 } 113 for (int m = 0; m < a.length - 2; m++) { 114 for (int n = m + 1; n < a.length - 2; n++) { 115 if (a[m] > a[n]) { 116 int temp1 = a[m]; 117 a[m] = a[n]; 118 a[n] = temp1; 119 } 120 } 121 } 122 while (i > 4 && i < 7) { 123 int k = (int) (Math.random() * 12) + 1; 124 boolean temp2 = true; 125 for (int e = 5; e < 7; e++) { 126 if (a[e] == k) { 127 temp2 = false; 128 } 129 } 130 if (!temp2) { 131 continue; 132 } 133 a[i] = k; 134 i++; 135 } 136 for (int m = 5; m < 7; m++) { 137 for (int n = m + 1; n < 7; n++) { 138 if (a[m] > a[n]) { 139 int temp1 = a[m]; 140 a[m] = a[n]; 141 a[n] = temp1; 142 } 143 } 144 } 145 for (int n : a) { 146 sb2.append(n + ","); 147 } 148 } 149 150 public void qixing() { 151 int[] a = new int[7]; 152 for (int j = 0; j < 7; j++) { 153 int b = (int) (Math.random() * 10); 154 a[j] = b; 155 } 156 for (int n : a) { 157 sb3.append(n + ","); 158 } 159 160 } 161 }
xml文件:
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/RelativeLayout1" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 tools:context="com.lixu.caipiao.MainActivity" > 8 9 <EditText 10 android:id="@+id/et1" 11 android:layout_width="210dp" 12 android:layout_height="50dp" 13 android:hint="等待输入" 14 android:background="@drawable/round"/> 15 16 <EditText 17 android:id="@+id/et2" 18 android:layout_width="210dp" 19 android:layout_height="50dp" 20 android:layout_below="@id/et1" 21 android:hint="等待输入" 22 android:background="@drawable/round" 23 /> 24 25 <EditText 26 android:id="@+id/et3" 27 android:layout_width="210dp" 28 android:layout_height="50dp" 29 android:layout_below="@id/et2" 30 android:hint="等待输入" 31 android:background="@drawable/round"/> 32 33 34 <Button 35 android:id="@+id/btn1" 36 android:layout_width="wrap_content" 37 android:layout_height="wrap_content" 38 android:layout_alignParentRight="true" 39 android:layout_alignParentTop="true" 40 android:text="双色球机选" 41 android:background="@drawable/round"/> 42 43 <Button 44 android:id="@+id/btn2" 45 android:layout_width="wrap_content" 46 android:layout_height="wrap_content" 47 android:layout_alignBaseline="@+id/et2" 48 android:layout_alignBottom="@+id/et2" 49 android:layout_alignParentRight="true" 50 android:text="大乐透机选" 51 android:background="@drawable/round"/> 52 53 <Button 54 android:id="@+id/btn3" 55 android:layout_width="wrap_content" 56 android:layout_height="wrap_content" 57 android:layout_alignParentRight="true" 58 android:layout_below="@+id/btn2" 59 android:text="七星彩机选" 60 android:background="@drawable/round"/> 61 </RelativeLayout>
运行效果图:
时间: 2024-10-27 10:39:36