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