Created
June 20, 2012 11:54
-
-
Save nyuichi/2959529 to your computer and use it in GitHub Desktop.
じゃんけん
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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