一问题:
二具体代码:
package 重修;import java.util.Random;
import java.util.Scanner;public class first {public static void main(String[] args) {int []usersnumbers=usernumslect();System.out.println("用户");for (int i = 0; i < 7; i++) {System.out.print(usersnumbers[i]+" ");}System.out.println();int []lucknumber=creatluvknumber();System.out.println("官方");for (int i = 0; i < 7; i++) {System.out.print(lucknumber[i]+" ");}System.out.println();judge(usersnumbers,lucknumber);}private static void judge(int[] usersnumbers, int[] lucknumber) {int num1=0,num2=0;for (int i = 0; i < usersnumbers.length-1; i++) {if(usersnumbers[i]==lucknumber[i]) num1++;}if(usersnumbers[6]==lucknumber[6]) num2++;System.out.println("您命中的红环球数量是"+num1);System.out.println("您命中的篮球数量是"+num2);if(num2==0){if(num1==4||num1==5) System.out.println("恭喜您,中将100元");if(num1==6) System.out.println("恭喜您中将1万元");else System.out.println("遗憾,未中奖");}else{switch (num1){case 0:case 1:System.out.println("恭喜您,中将5元");break;case 2:case 3:System.out.println("恭喜您,中将10元");break;case 4: System.out.println("恭喜您,中将100元");break;case 5: System.out.println("恭喜您,中将1000元");break;case 6: System.out.println("恭喜您,中将1万元");break;}}}private static int[] creatluvknumber() {Random sb=new Random();int[]nums=new int[7];int t;for (int i = 0; i < nums.length; i++) {nums[i]=-1;}out:for (int i = 0; i < nums.length-1; i++) {t= sb.nextInt(33)+1;for (int j = 0; j < nums.length-1; j++) {if(nums[j]==t){i--;continue out;}}nums[i]=t;}nums[nums.length-1]=sb.nextInt(16)+1;return nums;}private static int[] usernumslect() {Scanner sc=new Scanner(System.in);int t;int[]nums=new int[7];for (int i = 0; i < nums.length; i++) {nums[i]=-1;}for (int i = 0; i < nums.length-1; i++) {System.out.println("请用户决定投注第"+(i+1)+"号号码(1~33)");t= sc.nextInt();for (int j = 0; j < nums.length-1; j++) {if(nums[j]==t){System.out.println("投注重复号码,请重新输入~");i--;break;}if(t<1||t>33){System.out.println("投注超出范围,请重新输入~");i--;break;}}nums[i]=t;}while (true) {System.out.println("请决定蓝色球号码");t= sc.nextInt();if(t<1||t>16){System.out.println("投注超出范围,请重新输入~");}else {nums[6]=t;break;}}return nums;}}
三运行结果: