Java Scissors mini-game (scissors, stone, cloth)

Source: Internet
Author: User

Import Java.util.random;import Java.util.scanner;public class Caiquan{public static void Main (string[] args) {Random r= New Random (); int Diannao=r.nextint (3) +1; Scanner s=new Scanner (system.in); System.out.println ("========= scissors mini-game ========="); System.out.println ("Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth"); int fangke=s.nextint (); if (diannao==1&&fangke==1) { SYSTEM.OUT.PRINTLN ("The computer is a pair of scissors, you have scissors, a draw");} if (diannao==1&&fangke==2) {System.out.println ("The computer out of the scissors, you out of the stone, you Win");} if (diannao==1&&fangke==3) {System.out.println ("The computer out of the scissors, you out of the cloth, the computer wins");} if (diannao==2&&fangke==1) {System.out.println ("The computer is out of stone, you have scissors, the computer Wins");} if (diannao==2&&fangke==2) {System.out.println ("The computer is out of stone, you have a stone, a draw");} if (diannao==2&&fangke==3) {System.out.println ("The computer is out of stone, you are out of cloth, you Win");} if (diannao==3&&fangke==1) {System.out.println ("The computer out of the cloth, you out of the scissors, you Win");} if (diannao==3&&fangke==2) {System.out.println ("The computer out of the cloth, you out of the stone, the computer Wins");} if (diannao==3&&fangke==3) {System.out.println ("The computer is out of cloth, you are out of cloth, Draw");} if (FANGKE!=1&Amp;&fangke!=2&&fangke!=3) {System.out.println ("can only enter 1, 2, 3");}}} 
=============================================

C:\Documents and Settings\administrator>d:

D:\>CD JAVACX

D:\javacx>javac Caiquan.java

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
1
The computer out of the stone, you out of the scissors, the computer won

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
1
The computer out of the stone, you out of the scissors, the computer won

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
1
The computer out of the stone, you out of the scissors, the computer won

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
1
The computer is scissors, you have scissors, draw

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
1
The computer out is the cloth, you out of the scissors, you win

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
2
The computer out is the scissors, you out of the stone, you win

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
3
The computer out is the stone, you out of the cloth, you win

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
2
The computer is a stone, you have a rock, a draw.

D:\javacx>java Caiquan
========= Scissors Mini Game =========
Please enter 1, 2, 3, 1 for scissors, 2 for stone, 3 for cloth
8
You can only enter 1, 2, 3

D:\javacx>

  

Java Scissors mini-game (scissors, stone, cloth)

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.