じゃんけんをするプログラムで、人かコンピュータのどちらかが3回勝ったら終了したいのですが、なぜか人とコンピュータどちらも3回勝たないと終了できません。
どこが悪いのでしょうか?
よろしくお願いします。
java
1import java.util.Scanner; 2import java.util.Random; 3public class Janken { 4 public static void main(String args[]) { 5 Scanner stdln = new Scanner(System.in); 6 Random rand = new Random(); 7 int humancount=0; 8 int computarcount=0; 9 10 while(humancountc<3 || computarcount<3) { 11 12 int c = rand.nextInt(3); 13 System.out.println("じゃんけんをする"); 14 System.out.println("手(0:グー/1:チョキ/2:パー)を入力"); 15 int h = stdln.nextInt(); 16 17 switch(h) { 18 case 0: System.out.println("人:グー"); break; 19 case 1: System.out.println("人:チョキ"); break; 20 case 2: System.out.println("人:パー"); break; 21 } 22 23 switch(c) { 24 case 0: System.out.println("コンピュータ:グー"); break; 25 case 1: System.out.println("コンピュータ:チョキ"); break; 26 case 2: System.out.println("コンピュータ:パー"); break; 27 } 28 29 if(c==h) { 30 System.out.println("あいこ"); 31 }else if(c==0 && h==1 || c==1 && h==2 || c==2 && h==0) { 32 System.out.println("コンピュータの勝ち"); 33 computarcount++; 34 }else{ System.out.println("人の勝ち"); 35 humancount++; 36 } 37 } 38 } 39} 40 41 42 43
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/22 04:52