Skip to content

Instantly share code, notes, and snippets.

@d-kanazawa
Created February 1, 2015 15:47
Show Gist options
  • Save d-kanazawa/843637e64de153bb1e13 to your computer and use it in GitHub Desktop.
Save d-kanazawa/843637e64de153bb1e13 to your computer and use it in GitHub Desktop.
public class janken {
public static void main(String[] args){
int a =0;
int b =0;
String aite ="";
String jibun="";
for(int i =0;i <5;i--){
int CPU =(int)(Math.random()*3+1);
System.out.printf("1 グー%n2 チョキ%n3 パー%n");
String line = System.console().readLine();
int janken=Integer.parseInt(line);
switch(CPU){
case 1:
aite= ("グー");
break;
case 2:
aite =("チョキ");
break;
case 3:
aite =("パー");
break;
}
switch (janken){
case 1:
jibun=("グー");
break;
case 2:
jibun =("チョキ");
break;
case 3:
jibun=("パー");
break;
}
System.out.println("自分 "+jibun);
System.out.println("相手 "+aite);
switch (janken){
case 1:
if(CPU==1){
System.out.println("あいこです");
}
if(CPU==2){
System.out.println("勝ちです");
a = a+1;
}
if(CPU==3){
System.out.println("負けです");
b =b+1;
}
break;
case 2:
if(CPU==1){
System.out.println("負けです");
b=b+1;
}
if(CPU==2){
System.out.println("あいこです");
}
if(CPU==3){
System.out.println("勝ちです");
a=a+1;
}
break;
case 3:
if(CPU==1){
System.out.println("勝ちです");
a=a+1;
}
if(CPU==2){
System.out.println("負けです");
b=b+1;
}
if(CPU==3){
System.out.println("あいこです");
}
break;
}
while(b>=5){
i=10;
}
}
double c =a+b;
System.out.println("勝った回数"+a);
System.out.println("負けた回数"+b);
System.out.println("勝率"+a/c*100+"%");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment