[問題] 請問一些問題
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
--
Sent from my Android
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.47.103.96
※ 文章網址: http://www.ptt.cc/bbs/java/M.1418658056.A.308.html
推
12/15 23:49, , 1F
12/15 23:49, 1F
→
12/15 23:56, , 2F
12/15 23:56, 2F
※ 編輯: k7245313 (114.47.103.96), 12/16/2014 00:03:55
→
12/16 00:05, , 3F
12/16 00:05, 3F
→
12/16 07:50, , 4F
12/16 07:50, 4F
→
12/16 07:50, , 5F
12/16 07:50, 5F
→
12/16 07:51, , 6F
12/16 07:51, 6F
→
12/16 07:52, , 7F
12/16 07:52, 7F
→
12/16 07:52, , 8F
12/16 07:52, 8F
→
12/16 10:27, , 9F
12/16 10:27, 9F
推
12/16 13:23, , 10F
12/16 13:23, 10F
→
12/16 13:24, , 11F
12/16 13:24, 11F