zoukankan      html  css  js  c++  java
  • 课后习题

    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 课后提1
    {
        class Program
        {
            static void Main(string[] args)
            {
        //        //用户输入姓名,然后打印此人的年龄,从1岁-18岁,每一岁占一行,打印内容为“我今年xxx岁了!”;
        //当6岁时增加打印“我上小学了!”;
        //当11岁时增加打印“我上初中了!”;
        //当15岁时增加打印“我上高中了!”;
        //当18岁时增加打印“我成年了!考上了北大!”;
    
                Console.Write("请输入你的姓名:");
                string b = Console.ReadLine();
               
                for (int  i=1; i<= 18; i++)
                {
                    if (i==6)
                    {
                        Console.WriteLine("我叫"+b+",我今年" + i + "岁了,我上小学了!");
                    }
                    else if (i == 11)
                    {
                        Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我上初中了!");
                    }
                    else if (i == 15)
                    {
                        Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我上高中了!");
                    }
                    else if (i == 18)
                    {
                        Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我成年了!我上了北大!");
                    }
                    else
                    {
                        Console.WriteLine("我叫" + b + ",我今年" + i + "岁了");
                    }
                }
                
                Console.ReadLine();
            }
        }
    }
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 课后题4
    {
        class Program
        {
            static void Main(string[] args)
            {
    
    
                    //让用户循环操作,用户输入一个正整数(0-20),如果小于0或大于20都提示输入错误,
                    //如果输入的是0-20之间的数,那么就打印从0到这个数的累加求和,
                    //一共需要用户输入3遍,输入错误不计入这3遍操作当中
                int count = 0;
                 //让用户循环输入
                for (int i = 0; i < 10;i++ )
                {
                    if (count>=3)
                    {
                        break;//跳出循环。终止所有的循环。
                    }
                    Console.Write("请输入一个正整数(0-20):");
                    int a = int.Parse(Console.ReadLine());
                    //判断用户输出的数
                    if (a >= 0 && a <= 20)
                    {
                         //如果输出正确,那么累加求和并输出
                        int sum = 0;
                        for (int j = 0; j <= a;j++ )
                        {
                            sum += j;
                        }
                        Console.WriteLine (sum);
                        //判断用户当前输入了几遍
                        count++;
    
                        Console.WriteLine("您当前输入第"+count +"");
                    }
                    else
                    {
                        Console.WriteLine("你的输入有误");
                    }
    
                }
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    mac PHP安装imageMagic扩展
    使用AWS Lambda,API Gateway和S3 Storage快速调整图片大小
    composer Changed current directory to没反应
    mongodb批量update更新数据
    php 判断图片文件的真实类型
    C#选择文件、选择文件夹、打开文件(或者文件夹)
    C#连接数据库
    湿寒阳虚体质如何艾灸
    女人艾灸穴位
    四个穴位掌控全身健康
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5472546.html
Copyright © 2011-2022 走看看