• while循环练习-不断要求用户输入数字,当用户输入"end"时,输出最大值。


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace while4_求最大值
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //不断要求用户输入数字(假定用户输入的都是整数),当用户输入end的时候,输出最大值。
    14             //循环体:提示用户输入一个数字,接收、转换成int类型,比较大小。
    15             //循环条件:输入的不能是end
    16             string input = "";
    17             int max = 0;
    18             while (true)
    19             {
    20                 Console.WriteLine("请输入一个数字,输入end时,输出最大值:");
    21                 input = Console.ReadLine();
    22                 try
    23                 {
    24                     if (input != "end")
    25                     {
    26                         int number = Convert.ToInt32(input);
    27                         if (number >= max)
    28                         {
    29                             max = number;
    30                         }
    31                     }
    32                     else
    33                     {
    34                         Console.WriteLine("您输入的最大值是{0}.", max);
    35                         break;
    36                     }
    37                 }
    38                 catch
    39                 {
    40                     Console.WriteLine("输入内容与要求不匹配,请重新输入:");
    41                 }
    42             }
    43             Console.ReadKey();
    44         }
    45     }
    46 }
    ------ 一件事情没有准备好,千万不要开始,一旦开始,就一定不要停止!自己决定的事情就一定要完成,不管付出多大的代价! ------
  • 相关阅读:
    POJ 3126 Prime Path
    POJ 2429 GCD & LCM Inverse
    POJ 2395 Out of Hay
    【Codeforces 105D】 Bag of mice
    【POJ 3071】 Football
    【POJ 2096】 Collecting Bugs
    【CQOI 2009】 余数之和
    【Codeforces 258E】 Devu and Flowers
    【SDOI 2010】 古代猪文
    【BZOJ 2982】 combination
  • 原文地址:https://www.cnblogs.com/zhjason/p/13805108.html
Copyright © 2020-2023  润新知