The program of playing scissors with the computer in the loop mode (setting the winning condition--losing 3 times or winning 3 times is the exit)
/*int a=0;//Statistics win times
int b=0;//Statistics of the number of outputs
for (;;) {
SYSTEM.OUT.PRINTLN ("Please input 1, stone; 2, scissors; 3, cloth");
int User=sc.nextint ();//declaring user input
int cp= (int) (Math.random () *3+1);//DECLARE Computer random
Switch (user) {
Case 1:
System.out.println ("User out of stone");
Break
Case 2:
System.out.println ("User Out of Scissors");
Break
Case 3:
System.out.println ("User out of cloth");
Break
}
Switch (CP) {
Case 1:
SYSTEM.OUT.PRINTLN ("Computer Out of stone");
Break
Case 2:
SYSTEM.OUT.PRINTLN ("Computer out Scissors");
Break
Case 3:
SYSTEM.OUT.PRINTLN ("Computer Out of cloth");
Break
}
if (user==1&&cp==2| | user==2&&cp==3| | User==3&&cp==1) {
SYSTEM.OUT.PRINTLN ("user wins");
a++;
User wins
}
else if (user==1&&cp==3| | user==2&&cp==1| | user==3&&cp==2) {
Computer win
SYSTEM.OUT.PRINTLN ("computer wins");
b++;
}else if (USER==CP) {
System.out.println ("Draw");
}else{
System.out.println ("The number you entered is not valid");
}
if (a==3) {
SYSTEM.OUT.PRINTLN ("User wins three times, ends");
Break
}
else if (b==3) {
SYSTEM.OUT.PRINTLN ("Computer wins three times, ends");
Break
}
}
This article from "12159966" blog, declined reprint!
Java program for playing scissors with the computer in a cyclic way