• C# 语句 ---Swtich case (猜拳游戏)


    Swtich   case必须与break一起使用。

    Random r = new Random();
    int a = r.Next(1, 4);//甲选手 随机数
    int b = r.Next(1, 4); //乙选手 随机数
    string x = "", y = "";
    switch (a)
    {
    case 1:
    x = "剪刀";
    break;
    case 2:
    x = "石头";
    break;
    case 3:
    x = "布";
    break;
    default:
    break;
    }
    Console.WriteLine("甲选手出" + x);
    switch (b)
    {
    case 1:
    y = "剪刀";
    break;
    case 2:
    y = "石头";
    break;
    case 3:
    y = "布";
    break;
    default:
    break;
    }
    Console.WriteLine("乙选手出" + y);

    if (a > b)
    {
    if (a == 3 && b == 1)
    {
    Console.WriteLine("乙选手赢");
    }
    else
    {
    Console.WriteLine("甲选手赢");
    }
    }
    else if (a < b)
    {
    if (b == 3 && a == 1)
    {
    Console.WriteLine("甲选手赢");
    }
    else
    {
    Console.WriteLine("乙选手赢");
    }
    }
    else
    {
    Console.WriteLine("甲乙选手平局");
    }
    Console.ReadLine();

  • 相关阅读:
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
    牛客网每日一练
  • 原文地址:https://www.cnblogs.com/likaixuan/p/4331634.html
Copyright © 2020-2023  润新知