?? game2.java
字號:
import java.util.*;
import java.lang.String;
import mypg.InputData;
class Game2 {
public static int[] Game(int max,int N){
int index;
int[] a = new int[max];
Random test = new Random();
for(index=0; index<a.length; index++){
a[index]=index+1;
}
index--;
int tempIndex, tempCon;
for(; index>=0; index--){
tempIndex = test.nextInt(a.length);
tempCon = a[index];
a[index] = a[tempIndex];
a[tempIndex] = tempCon;
}
System.out.println("彩票開獎號碼:");
for(int i=0; i<N; i++){
a[i]=a[i]-1;
System.out.print(a[i]+" ");
}
System.out.println();
return a;
}
public void game(){
int Number[] = new int [7];
int c[] = new int [21];
String str = new String();
String str1 = new String();
String str2 = new String();
int count=0,t=-1;
// c=Game(10,7);
System.out.println("請從0~9中選7個數(shù)輸入:");
for(int i=0;i<7;i++){
Number[i]=InputData.iRead();
};
c=Game(10,7);
for(int i=0;i<7;i++){
str1 +=""+c[i];
str2 +=""+Number[i];
}
// System.out.println(str1);
// System.out.println(str2);
Rep:
for(int i=6;i>=0;i--){
for(int j=0;j<i;j++){
str=str1.substring(j,i);
if(str2.indexOf(str,0)!=t){
// System.out.println(str2.indexOf(str,0));
// System.out.println(str);
count=str.length();
break Rep;
}
}
}
System.out.println("您買的彩票號碼:");
for(int i=0; i<7; i++){
System.out.print(Number[i]+" ");
}
System.out.println();
switch(count){
case 7:System.out.println("恭喜你中了特等獎!");
break;
case 6:System.out.println("恭喜你中了一等獎!");
break;
case 5:System.out.println("恭喜你中了二等獎!");
break;
case 4:System.out.println("恭喜你中了三等獎!");
break;
case 3:System.out.println("恭喜你中了四等獎!");
break;
default:System.out.println("很遺憾,本次你沒有中獎!");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -