经过短短两周的学习过程,对java有了初步的了解,讲实话当初对java感兴趣是因为在某音刷到了某培训中心的广告,去他们那里了解力一下,起初也是带着困惑和未知,可能也是对游戏比较敢兴趣当我了解到Java是可以做游戏的比如飞机大战,心里便产生浓浓的兴趣和向往,在开始深入了解之后几遍知道游戏方面c++才是主流,也阻止不了我对java编程浓浓的热爱.
后来在通过朋友的介绍知道了黑马,经过客方面考虑我选择来的这里,来实现我的向往,对于学习变成我现在只有冲冲冲一直不能停.
作为编程菜鸟的我,在新人技术贴我也内什么好展示,给大家分享下我实现过最多行的代码吧.
双色球案例:
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class Testss1{
public static void main(String[] args){
int[] userRedBall=new int[6];
int[] sysRedBall=new int[6];
int userBlueBall=0;
int sysBlueBall=0;
int redCount=0;
int blueCount=0;
int[] redBall=new int[33];
for(int i=0;i<redBall.length;i++){
redBall[i]=i+1;
}
System.out.println("双色球游戏开始");
System.out.println("请问您是要手选还是机选(1:机选,2手选)");
Scanner input=new Scanner(System.in);
Random r =new Random();
boolean flag =true;
while(flag){
int isAuto=input.nextInt();
switch(isAuto){
case 1:
computerSelection(redBall,userRedBall);
userBlueBall=r.nextInt(16)+1;
flag=false;
break;
case 2:
System.out.println("请选择6个红球号码(1-33)");
for(int i=0;i<userRedBall.length;i++){
userRedBall[i]=input.nextInt();
}
System.out.println("请选择1个蓝球号码(1-16)");
userBlueBall=input.nextInt();
flag=false;
break;
default:
System.out.println("请问您是要手选还是机选(1:机选,2手选)");
break;
}
}
computerSelection(redBall,sysRedBall);
sysBlueBall=r.nextInt(16)+1;
for(int i=0;i<userRedBall.length;i++){
for(int j=0;j<sysRedBall.length-redCount;j++){
if(userRedBall[i]==sysRedBall[j]){
int x=sysRedBall[j];
sysRedBall[j]=sysRedBall[sysRedBall.length-1-redCount];
sysRedBall[sysRedBall.length-1-redCount]=x;
redCount++;
}
}
}
if(userBlueBall==sysBlueBall){
blueCount=1;
}
if(blueCount ==0 && redCount<=3){
System.out.println("革命尚未成功");
}else if(blueCount==1&& redCount<3){
System.out.println("恭喜六等奖,5元");
}else if((blueCount==1 && redCount==3)||(blueCount==0 && redCount==4)){
System.out.println("恭五等奖,10元");
}else if((blueCount==1&&redCount==4)||(blueCount==0&&redCount==5)){
System.out.println("恭四等奖,200元");
}else if(blueCount==1&&redCount==5){
System.out.println("恭喜三等奖,3000元");
}else if(blueCount==0&&redCount==6){
System.out.println("恭喜二等奖,150w元");
}else if(blueCount==1&&redCount==6){
System.out.println("恭喜一等奖,500w元");
}else{
System.out.println("系统有误,中奖无效");
}
System.out.println("本期中奖红球号码为:");
sort(sysRedBall);
System.out.println(Arrays.toString(sysRedBall));
System.out.println("本期中奖蓝球号码为:"+sysBlueBall);
System.out.println("本期您的红球号码为:");
sort(userRedBall);
System.out.println(Arrays.toString(userRedBall));
System.out.println("本期您的蓝球号码为:"+userBlueBall);
System.out.println("感谢参与");
}
public static void sort(int[] ball){
for(int i=0;i<ball.length-1;i++){
for(int j=0;j<ball.length-1-i;j++){
if(ball[j]>ball[j+1]){
ball[j]=ball[j]+ball[j+1];
ball[j+1]=ball[j]-ball[j+1];
ball[j]=ball[j]-ball[j+1];
}
}
}
}
public static void computerSelection(int[] redBall,int[] userRedBall){
Random r=new Random();
int index=-1;
for(int i=0;i<userRedBall.length;i++){
index=r.nextInt(redBall.length-i);
userRedBall[i]=redBall[index];
int x=redBall[index];
redBall[index]=redBall[redBall.length-1-i];
redBall[redBall.length-1-i]=x;
}
}
}
|
|