A handbook for front-end engineers--Basic Learning--c#

Source: Internet
Author: User
Tags square root

Practice--judging parity

Application of logical operation

static void Main (string[] args)

{

Console.Write ("\ n Please enter an integer, press ENTER to determine the parity:");
int a = Int. Parse (Console.ReadLine ()), B = a% 2;
BOOL C = b = = 0;
String d = c? "The integer is even": "The integer is odd";
Console.Write ("\ n" +d+ "\ n");
Console.ReadLine ();
}

About operations

One, + + and in arithmetic operations--

+ + read as "Gaga", written in two ways: a++ and ++a.

a++: Get a value that is the same as the variable and add 1 to the variable;

++a: Get a value that is 1 larger than the variable and add 1 to the variable.

My understanding of the method: a++ (or ++a) as a whole, this whole is a number, but this is a number with other functions, its function is: Add the variable 1; What is this number? When writing a a++, its value is equal to the value of the variable, and when writing ++a, its value is 1 more than the value of the variable. As a number to understand, like the square root 4, it is a number, this number equals a few? Equal to 4 square, that is, 2;3 cubic, etc., it is a number, this number equals a few? Equals 3*3*3=9.

Two or three mesh operation

The trinocular operation is a kind of logical operation, this is a good thing ah! It can provide selective output.

A?b:c where A is a bool value, B and C are any amount, but the type is the same.

This means: When a is true, output B, otherwise output c.

Third, health calculator

Here's what I'm writing:

static void Main (string[] args)
{
Console.Write ("\n\t\t Health calculator \ n");//Title
Console.Write ("\n\t Please enter your gender (male or female):");
string sex = Console.ReadLine ();//Get gender, string
Console.Write ("\n\t Please enter your height (cm):");
int height =int. Parse (Console.ReadLine ());//Get height string, turn to integer assign value to Heigh
Console.Write ("\n\t Please enter your weight (kg):");
int weight =int. Parse (Console.ReadLine ());//Get weight string, turn to integer assignment to weight
bool A = Sex = = "male";//Contrast input sex is not male
Double Resule = a? 0.7 * (HEIGHT-80): 0.6 * (HEIGHT-70);/ * is a male with the first formula, otherwise the second result is implicitly converted to a double, assigned to resule*/
BOOL B = resule > Weight * (1 + 0.1);//Compare the result resule with the overweight standard and get a Boolean b
BOOL C = Resule < weight * (1-0.1);//Compare the results to the thin standard and get a Boolean C
bool D =!b &&!c;//The Boolean that is neither B nor C (that is, between the radicals and the lean) is assigned to D//resule <= weight * (1 + 0.1) && resule >= weight * (1-0.1);
string x = b? "Your body is overweight": "Your body is thin";
String y = d? "Your health, please keep ~": x;
Console.Write ("\n\t" +y+ "\ n");
Console.ReadLine ();
}

A handbook for front-end engineers--Basic Learning--c#

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.