⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game2.java

📁 首先提示用户选择玩法 玩法1:21选5 输入5个数(从1
💻 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个数输入:");
		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 + -