Skip to content

Instantly share code, notes, and snippets.

@tanakaedu
Last active November 18, 2015 05:05
Show Gist options
  • Save tanakaedu/da727b9f7ea647816a66 to your computer and use it in GitHub Desktop.
Save tanakaedu/da727b9f7ea647816a66 to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
public class Janken {
static Random rg = new Random();
public static void main(String[] args) throws Exception {
int comp;
String result = ""; // 結果の文字列
String compjp = ""; // コンピュータの手の日本語
// ぐー ちょき ぱー
// 入力
// 0~2までの乱数をint型の変数compに求める
comp=rg.nextInt(3);
// 試しで、変数compを出力する
System.out.println(""+comp);
// compの値から、compjpを求める
//// compが0だったらcompjpに ぐー と代入
if(comp == 0)
compjp = "ぐー";
if(comp == 1)
compjp = "ちょき";
if(comp == 2)
compjp = "ぱー";
// Here your code !
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
// 処理:判定
// コンピューターとプレイヤーが等しいか
if(compjp.equals (line))
result = "あいこ";
else if(compjp.equals("ぐー") && line.equals("ぱー")
|| compjp.equals("ぱー") && line.equals("ちょき")
|| compjp.equals("ちょき") && line.equals("ぐー") )
result="あなたの勝ち";
else
result = "あなたの負け";
// 出力
System.out.println("コンピューター:"+compjp);
System.out.println("結果:"+result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment