Little white to help you, great gods. C#while Cycle Usage

Source: Internet
Author: User

********************************************************************************************

Today, the teacher out of a problem, asked to use C # 's while statement to write the following code

The user is constantly asked to enter an integer that displays the maximum value of the number that was just entered when the user enters end.

I wrote a, I feel there is no problem, but the input end is always error, solve, thank you

1             intmax=0;2             strings ="";3              while(s!="End")4             {5Console.WriteLine ("Please enter a number");6s =console.readline ();7                 intNumber =Convert.ToInt32 (s);8 9                 if(Number >max)Ten                 { OneMax =Number ; A                 } -             } -             theConsole.WriteLine (max);


The following again wrote a There is no problem, stay for the students just learn reference.
1              intMax =0;2              while(true)3             {4Console.WriteLine ("Please enter a number (end Please enter end):");5                 strings =console.readline ();6                 if(s = ="End")7                      Break;8                 intNumber =Convert.ToInt32 (s); 9                 if(Number >max)Ten                { OneMax =Number ; A                 } -  -                 the             } -  -Console.WriteLine ("The maximum value you entered earlier is {0}", max); -Console.readkey ();

Little white to help you, great gods. C#while Cycle Usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.