自由研究 第4回目

こんにちは。

 

今日も自由研究について書いていきたいと思います。

じゃんけんのプログラムを調べました。

 

 

import java.io.*;

class janken {
public static void main(String argv[]) {
BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
int i, xx;
int you = 0;

saikoro sa = new saikoro();

for (i = 1; i <= 5; i++) {

xx = sa.sainome();

System.out.print("\n\tgu = 1 choki= 2 pa = 3 を入れる ");

try {
you = Integer.parseInt(d.readLine());
} catch (IOException e) {
}
System.out.println("\t\tコンピュータは " + xx + " あんたは " + you + " \n");

if (you == xx)
System.out.println(" 引き分け");

else if (you + 1 == xx)
System.out.println(" あなたの勝ち");

else if (xx + 1 == you)
System.out.println(" コンピュータの勝ち");

else if *1
System.out.println(" あなたの勝ち");

else if *2
System.out.println(" コンピュータの勝ち");

}
}
}

///// ジャンケンの 1 2 3 の どれかを返す /////
class saikoro {
public int sainome() {
int yy = (int) (Math.random() * 3) + 1;

return ( yy );
}
}

 

以上です。

*1:you == 3) && (xx == 1

*2:xx == 3) && (you == 1