评委打分
importjava.util.Scanner;
publicclassJavaDemoDay6Example3{
publicstaticvoidmain(String[]args){
//评委打分
System.out.println("请输入评委的人数:");
Scannersc=newScanner(System.in);
intn=sc.nextInt();
System.out.println("最终选手的得分为:"+scores(n));
}
publicstaticdoublescores(intn){
double[]score=newdouble[n];
Scannersc=newScanner(System.in);
System.out.println("请输入各位评委的评分:");
for(inti=0;i
score[i]=sc.nextDouble();
}
//获取最高分
doublemaxScore=score[0];
for(inti=0;i
if(maxScore<=score[i]){
maxScore=score[i];
}
}
//获取最低分
doubleminScore=score[0];
for(inti=0;i
if(minScore>=score[i]){
minScore=score[i];
}
}
//记录选手的总分
doublesum=0;
for(inti=0;i
sum+=score[i];
}
doublelastScore=(sum-minScore-maxScore)/(n-2);
returnlastScore;
}
}
双色球
importjava.util.Random;
importjava.util.Scanner;
publicclassJavaDemoDay6Example10_3{
publicstaticvoidmain(String[]args){
checkLast(selectNum(),luckNum());
}
publicstaticint[]selectNum(){
int[]nums={0,0,0,0,0,0,0};
Scannersc=newScanner(System.in);
//先获取前六个红球号码,要求在1-33范围,且不能重复
for(inti=0;i
System.out.println("请您输入第"+(i+1)+"个红球号码:");
inta=sc.nextInt();
while(true){
if(a>33||a<1){
System.out.println("对不起,您输入的红球号码范围有误,请您重新输入!");
a=sc.nextInt();
}else{
//判断是否重复
if(exist(a,nums)){
System.out.println("对不起,您输入的号码前面已经选择过了,请重新选择!");
a=sc.nextInt();
}else{
nums[i]=a;break;
}
}
}
}
System.out.println("请您输入一个蓝球号码:");
while(true){
intb=sc.nextInt();
if(b<1||b>16)
{
System.out.println("对不起,您输入的蓝球号码有误,请重新输入!");
}
else{nums[nums.length-1]=b;break;}
}
System.out.println(nums[6]);
returnnums;
}
publicstaticint[]luckNum(){
int[]luckNums={0,0,0,0,0,0,0};
Randomr=newRandom();
for(inti=0;i
intran=r.nextInt(33)+1;
while(true){
if(exist(ran,luckNums)){
ran=r.nextInt();
}
else
{
luckNums[i]=ran;
break;
}
}
}
intra=r.nextInt(1,17);
luckNums[6]=ra;
System.out.println(luckNums[6]);
returnluckNums;
}
//判断是否重复
publicstaticbooleanexist(inta,int[]nums){
for(inti=0;i
if(nums[i]==a){
returntrue;
}
}
returnfalse;
}
publicstaticvoidcheckLast(int[]selectNums,int[]luckNums){
//计算红球的命中率
intredCount=0;
for(inti=0;i
for(intj=0;j
if(luckNums[j]==selectNums[i]){
redCount++;
break;
}
}
}
System.out.println("红球的命中率为:"+redCount);
//判断蓝球的命中率
intblueCount=(luckNums[luckNums.length-1]==selectNums[selectNums.length-1]?1:0);
System.out.println("蓝球的命中率为:"+blueCount);
//分析中奖情况
if(redCount==6&&blueCount==1){
System.out.println("恭喜您,中奖1000万,可以开始享受人生了~~~");
}elseif(redCount==6&&blueCount==0){
System.out.println("恭喜您,中奖500万,可以稍微开始享受人生了~~~");
}elseif(redCount==5&&blueCount==1){
System.out.println("恭喜您,中奖3000元,可以出去吃顿小龙虾了~");
}elseif(redCount==5&&blueCount==0||redCount==4&&blueCount==1){
System.out.println("恭喜您,中了小奖:200元~");
}elseif(redCount==4&&blueCount==0||redCount==3&&blueCount==1){
System.out.println("中了10元~");
}elseif(redCount<3&&blueCount==1){
System.out.println("中了5元~");
}else{
System.out.println("感谢您对福利事业做出的巨大贡献~~");
}
}
}