zoukankan      html  css  js  c++  java
  • C# 11编程练习

    编程练习

    假设a、b两个变量交换值,需要先声明一个中间变量temp,用temp临时存储其中变量a的值,再将变量b的值赋值给a,最后将temp赋值给b。

    任务

    这段程序中有 2 个变量,分别存储了“今天的午饭”和“明天的午饭”。现在想要“今天吃小鸡炖蘑菇,明天吃鱼香肉丝”,请在代码中补充变量交换的代码。

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                string today;//今天的午饭
                string tomorrow;//明天的午饭
                today = "鱼香肉丝";
                tomorrow = "小鸡炖蘑菇";
                //请在这里补充代码,实现变量today和tomorrow的交换
                
                
                
                
                
                
                
                //打印
                Console.WriteLine("我今天吃{0},明天吃{1}。",today,tomorrow);
            }
        }
    }

    //交换today和tomorrow的值
    string temp;//中间变量
    temp = today;//今天的午饭赋值给temp
    today = tomorrow;//明天的午饭赋值给今天
    tomorrow = temp;//temp赋值给明天

  • 相关阅读:
    54.施工方案第二季(最小生成树)
    53.FIB词链
    52.1076 排序
    最短路径:我的理解--SPFA算法
    POJ2187Beauty Contest
    CodeForces 279B Books
    SDUT 2527 斗地主
    HDU1020 Encoding
    POJ 2635 The Embarrassed Cryptographer
    POJ 1942 Paths on a Grid(组合数)
  • 原文地址:https://www.cnblogs.com/wangdayang/p/15363626.html
Copyright © 2011-2022 走看看