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#