Java program for playing scissors with the computer in a cyclic way

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.