import java.util.*;
public class PM6_1 {
public static void main(String args[]){
int maxNum = 0,number = 0,num1,num2,num3,num4,name = 0;
int maxName=0;
Scanner keyin=new Scanner(System.in);
System.out.printf("请玩家输入姓名并掷骰子=>");
keyin.nextLine();
number=game();
System.out.printf("合计:%d\n",number);
System.out.printf("请玩家输入姓名并掷骰子=>");
keyin.nextLine();
number=game();
System.out.printf("合计:%d\n",number);
System.out.printf("请玩家输入姓名并掷骰子=>");
keyin.nextLine();
number=game();
System.out.printf("合计:%d\n",number);
System.out.printf("请玩家输入姓名并掷骰子=>");
keyin.nextLine();
number=game();
System.out.printf("合计:%d\n",number);
if (number>maxNum){
maxNum=number;
maxName=name;
}
maxNum=max(number,max(number,max(number,number)));
System.out.printf("\n恭喜!!%d 先生掷出%d赢得此局\n",maxName,ma
xN
}
static int game(){
Random random=new Random();
int k,sum=0,ran;
System.out.printf("\t您掷出=>");
for(k=1;k<=3;k++){
ran=1+random.nextInt(6);
System.out.printf("%d和",ran); //让掷出的数目中间有间
隔
sum=sum+ran;
}
System.out.printf("\n");
return sum;
}
static int max(int a,int b){
if (a>b)
return a;
else
return b;
}
}
http://i.imgur.com/0ggYnBB.jpg
我想写出图片那样,不过最大数跑的出来,但玩家姓名一直是0
麻烦各位指点一下,谢谢!
gist: https://gist.github.com/anonymous/602acd7cfabd46f9c53b