Skip to content

Instantly share code, notes, and snippets.

@nyuichi
Created June 20, 2012 11:54
Show Gist options
  • Save nyuichi/2959529 to your computer and use it in GitHub Desktop.
Save nyuichi/2959529 to your computer and use it in GitHub Desktop.
じゃんけん
import java.util.Scanner;
class Mygame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("じゃんけんしましょー。ぱーなら0 ぐーなら1 ちょきなら2 を入力して: ");
int a = sc.nextInt();
int b = (int)(Math.random()*3);
sc.nextLine();
System.out.println("きみは...");
sc.nextLine();
if (a == 0) {
System.out.println("ぱーでしたー");
} else if (a == 1) {
System.out.println("ぐーでしたー");
} else if (a == 2) {
System.out.println("ちょきでしたー");
}
sc.nextLine();
System.out.println("ぼくは...");
sc.nextLine();
if (b == 0) {
System.out.println("ぱーでしたー");
} else if (b == 1) {
System.out.println("ぐーでしたー");
} else if (b == 2) {
System.out.println("ちょきでしたー");
}
sc.nextLine();
System.out.println("結果は...");
sc.nextLine();
if (a == b) {
System.out.println("ひきわけでしたー");
} else if ((a == 0 && b == 1) || (a == 1 && b == 2) || (a == 2 && b == 0)) {
System.out.println("きみのかちだよー");
} else {
System.out.println("きみのまけだよー");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment