继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

Geek攻城猫
关注TA
已关注
手记 4
粉丝 3
获赞 23
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("你赢了!");}

    }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP