Scissors Game Java Basics

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)

Package eduask01;

Import java.util.*;

public class Rask03 {

public static void Main (String[]args) {

Scanner sc=new Scanner (system.in);

int m=0,n=0;//The number of wins or losses accumulated

for (;;) {//Dead loop for game

System.out.println ("Scissors game: 1." means stone 2. Means scissors 3. Indicate cloth. Please enter a number scissors ");

int Num=sc.nextint ();//I guess the fist

int num= (int) (Math.random () *3+1);//Computer random punch

Switch (num) {///own 3 cases and explain separately

Case 1:

System.out.println ("You Are out of stone:");

Case 2:

System.out.println ("You Are out of scissors:");

Case 3:

System.out.println ("You are out of cloth:");

}switch (Num) {//Computer 3 in case

Case 1:

SYSTEM.OUT.PRINTLN ("The computer is a stone:");

Case 2:

SYSTEM.OUT.PRINTLN ("Computer Out of Scissors:");

Case 3:

SYSTEM.OUT.PRINTLN ("Computer Out of a cloth:");

}

if (num==num) {//Decision Draw

System.out.println ("-_-draw");

}else if (num==1&&num==2| | num==2&&num==3| | Num==3&&num==1) {//Decision WINS

System.out.println ("^-^ Congratulations on your victory"); M+=1;

}else {System.out.println ("O-o is sorry you Lost"); n+=1;} The other is the case of loss.

if (m==3) {System.out.println ("You have won 3 innings have exited the scissors game"); Won 3 times.

else if (n==3) {System.out.println ("The computer has won 3 times you have exited the Scissors game"); Lost 3 times.

}

}

}

Scissors Game Java Basics

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.