Skip to content

Instantly share code, notes, and snippets.

@komo91
Created February 1, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komo91/cc7d682a08b9b68988bd to your computer and use it in GitHub Desktop.
Save komo91/cc7d682a08b9b68988bd to your computer and use it in GitHub Desktop.
import java.util.Random;
import java.util.Scanner;
public class janken {
public static void main(String[] args) {
Random rn = new Random();
System.out.println("じゃんけんします。10回負けるまで繰り返します。");
System.out.println("グーは1,チョキは2,パーは3");
System.out.println("なに出す?");
//aは勝利カウント,bは負けカウント,cはじゃんけんカウント,dは勝率
int a = 0;
int b = 0;
int c = 0;
while(b < 10) {
Scanner sc = new Scanner(System.in);
int zibun = sc.nextInt();
int aite = rn.nextInt(3) + 1;
if(zibun == 1 && aite == 2){
System.out.println("アナタの勝ちです。");
a++;
} else if(zibun == 2 && aite == 3){
System.out.println("アナタの勝ちです。");
a++;
} else if(zibun == 3 && aite == 1){
System.out.println("アナタの勝ちです。");
a++;
}
if(zibun == 1 && aite == 3){
System.out.println("アナタの負けです。");
b++;
} else if(zibun == 2 && aite == 1){
System.out.println("アナタの負けです。");
b++;
} else if(zibun == 3 && aite == 2){
System.out.println("アナタの負けです。");
b++;
}
if(zibun == 1 && aite == 1) {
System.out.println("あいこです。");
} else if(zibun == 2 && aite == 2) {
System.out.println("あいこです。");
} else if(zibun == 3 && aite == 3) {
System.out.println("あいこです。");
}
}
int d = c/a;
System.out.println("勝ち" + a + "勝,負け" + b + "敗,勝率" + d +"%");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment