前提・実現したいこと
初めて質問させていただきます。
javaでじゃんけんをするシステムを作っています。
3回勝負にしようとして、numという変数に勝ちなら+1、負けなら−1をすることで、三回勝負が終わった後に最終結果を表示したいのですが、何度試しても引き分けと出ます。
最初に代入した0からmethod内の処理がなされていないのでしょうか?
どのようにしたら反映されるようになるでしょうか?
該当のソースコード
java
1public class task{ 2 public static void main(String[] args){ 3 String[] a ={"グー","チョキ","パー"}; 4 System.out.println("じゃんけん、3回勝負です"); 5 int count = 0; 6 while(count < 3){ 7 System.out.println("1.グー, 2.チョキ, 3.パー"); 8 int i = new java.util.Scanner(System.in).nextInt(); 9 int Y = i - 1; 10 System.out.println("あなたは" + a[Y]); 11 int P = new java.util.Random().nextInt(3); 12 System.out.println("PCは" + a[P]); 13 int num += janken(Y,P); 14 count++; 15 if(count >= 3){ 16 System.out.println("3回勝負の結果"); 17 if(num == 0){ 18 System.out.println("引き分け"); 19 }else if(num < 0){ 20 System.out.println("PCの勝ち"); 21 }else if(num > 0){ 22 System.out.println("あなたの勝ち"); 23 } 24 } 25 } 26 } 27 public static int janken(int Y,int P){ 28 if(Y == P){ 29 System.out.println("あいこ"); 30 }else if((Y == 0 && P == 1)||(Y == 1 && P == 2)||(Y == 2 && P == 0)){ 31 System.out.println("あなたの勝ち"); 32 return 1; 33 }else if((P == 0 && Y == 1)||(P == 1 && Y == 2)||(P == 2 && Y == 0)){ 34 System.out.println("PCの勝ち"); 35 return -1; 36 } 37 } 38} 39 40
試したこと
java:13: エラー: ';'がありません
int num += janken(Y,P);
^
エラー1個
と出てしまいます。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/03 05:14