ITPub博客

首页 > IT职业 > IT职场 > 猜拳(石头剪刀布)游戏(Dome)

猜拳(石头剪刀布)游戏(Dome)

IT职场 作者:chunshui 时间:2021-09-09 09:10:53 0 删除 编辑
import java.util.Scanner;
public class guess {
public static void main(String[] args) {
    Scanner A=new Scanner(System.in);
    System.out.println("---猜拳游戏---");
    System.out.println("请出拳(1.石头,2.剪刀,3.布)");
    int people= A.nextInt();
    int computer=(int)(Math.random()*3+1);  

    if (people==1){
    System.out.println("你出的拳是:石头");}
    if (people==2){
        System.out.println("你出的拳是:剪刀");}
    if (people==3){
        System.out.println("你出的拳是:布");}

    if (computer==1){
        System.out.println("电脑出的拳是:石头");}
    if (computer==2){
        System.out.println("电脑出的拳是:剪刀");}
    if (computer==3){
        System.out.println("电脑出的拳是:布");}

    if (people==computer){
        System.out.println("平局");}
    else if(people==1&&computer==3||people==2&&computer==1||people==3&&computer==2)
    {
        System.out.println("电脑赢了! ");}
    else{
        System.out.println("你赢了!");}

    }
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3527/viewspace-2800032/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    98
  • 访问量
    1074