C # Statements: Branching

Source: Internet
Author: User

Vi.. Branches:
A
if (an expression)
{
}
Description
1. The expression is the expression used to return the bool shape.
Don't add a semicolon after the 2.if parenthesis

Two
if (an expression)
{
}
Else
{
}

Cases:
1. Enter age, greater than or equal to 18 show adult, otherwise show underage.
Ideas:

(1). Accept a number from the keyboard

(2). Determine if the above conditions are met
Year>=18
(3). Show adult or minor according to judgment


2. Display: Can you run over the leopard? Receive input, if the input is "can", you are more animals than animals. If the input "cannot" show the beast is inferior.
Ideas:

(1). Output text "Can you run over the leopard?" ”

(2). Receive text from the keyboard
(3). Determine if the above conditions are met
s== can
(4). Judging results show "You are more animals than animals", "You animals are inferior"


3. Let the user enter a year to determine whether it is leap years.
A. can be divisible by 400
B. can be divisible by 4, but not divisible by 100.
Ideas:
(1). Receives a year from the keyboard, and converts the whole number of years.
(2). Determine if the above two conditions are met.
(year%400 = = 0) | | (Year%4==0 && year%100!=0)
(3). Show "Common Year" "Leap year" according to the judging result


4. Standard weight (KG) = height (CM)-100 floating up and down 5 kg normal.
Enter the actual weight, enter the actual height, "standard" or "non-standard".
Ideas:
(1). Enter height (h) and weight (W).
(2). Calculate the standard weight = height-100. bw=h-100;
(3). Compare the standard weight to the actual weight. Bw-w>=-5 && bw-w<=5
(4). Display standard or not standard.

C # Statements: Branching

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.