じゃんけんで先に3回買った方が勝ちというプログラムを書いていますが、実行すると勝ち数が0になり、じゃんけんすら行われずに終了してしまいます。
どうすれば良いのでしょうか・・・
java
1import java.util.*; 2 3public class Janken2 { 4 public static void main(String[] args) { 5 Scanner stdIn = new Scanner(System.in); 6 Random rand = new Random(); 7 int w=0; 8 int l=0; 9 while(w>2 || l>2){ 10 System.out.print("手(0:グー/ 1: チョキ/ 2:パー) ? "); 11 12 int h = stdIn.nextInt(); 13 int c = rand.nextInt(3); 14 int j = (c-h+3)%3; 15 16 17 print("人",h); 18 print("こんぴゅーた",c); 19 20 switch(j) { 21 case 0: System.out.println("あいこ"); break; 22 case 1: System.out.println("人の勝ち"); w++; break; 23 case 2: System.out.println("コンピュータの勝ち"); l++; break; 24 } 25 26 27 } 28 System.out.println("あなたの勝ち数は"+w); 29 } 30 public static void print(String s, int x) { 31 32 switch(x) { 33 case 0: System.out.println(s+"グー"); break; 34 case 1: System.out.println(s+"チョキ"); break; 35 case 2: System.out.println(s+"パー"); break; 36 } 37 38 39 40 } 41 42} 43 44 45
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。