If () else () Statement in programming

Source: Internet
Author: User

Example () else ()

Double D = convert. todouble (console. Readline ());

If (D> = 60 & D <= 100)

{

Console. writeline ("pass ");

}

Else

{

Console. writeline ("fail ");

}

Console. Readline ();

 

Example

1. Rounding a floating point number to an integer.

 

Console. Write ("Enter :");

Double D = convert. todouble (console. Readline ());

If (D-(INT) d >=0.5)

{

D = (INT) D;

D ++;

}

Else

{

D = (INT) D;

}

Console. writeline ("Result:" + D. tostring ());

Console. Readline ();

 

 

 

2. Obtain the root of a quadratic equation (A * x + B * x + c = 0)

 

Console. writeline ("A * x + B * x + c = 0, the root of the equation ");

Console. Write ("Enter: A = ");

Double A = convert. todouble (console. Readline ());

Console. Write ("Enter B = ");

Double B = convert. todouble (console. Readline ());

Console. Write ("Enter: c = ");

Double C = convert. todouble (console. Readline ());

 

If (A = 0)

{

Console. writeline ("This is not a quadratic equation !!! ");

}

Else

{

Double DR = B * B-4 * a * C;

If (Dr> 0)

{

Double X1 = (-B + math. SQRT (DR)/2 *;

Double X2 = (-B-math. SQRT (DR)/2 *;

Int C1 = (INT) x1;

Int C2 = (INT) x2;

Console. writeline ("two unequal roots, X1 = {0}, X2 = {1}", C1, C2 );

}

If (DR = 0)

{

Double X = (-B)/2 *;

Int C3 = (INT) X;

Console. writeline ("there is a root, x =" + C3 );

}

If (Dr <0)

{

Console. writeline ("no real root! ");

}

}

Console. Readline ();

 

 

 

3. Determine whether the weight is standard (Men's Standard Weight = height-100 ± 3; Women's Standard Weight = height-110 ± 3)

 

Console. writeline ("Weight Detection Program ");

Console. Write ("Enter Gender :");

String x = convert. tostring (console. Readline ());

Console. Write ("Enter the weight (kg ):");

Double T = convert. todouble (console. Readline ());

Console. Write ("Enter height (CM ):");

Double S = convert. todouble (console. Readline ());

 

If (x = "male" | x = "female ")

{

If (x = "male ")

{

Double bzt1 = s-100 + 3; // bzt1 indicates the standard weight.

Double bzt2 = s-100-3; // bzt2 is the standard weight.

If (T> bzt1)

{

Console. writeline ("you can swim without a lifebuoy ");

}

Else if (T <= bzt1 & T> = bzt2)

{

Console. writeline ("good figure, continue to maintain ");

}

Else

{

Console. writeline (" ~ Eat more in the future ");

}

}

Else

{

Double bzt1 = s-110 + 3;

Double bzt2 = seconds-110-3;

If (T> bzt1)

{

Console. writeline ("you can swim without a lifebuoy ");

}

Else if (T <= bzt1 & T> = bzt2)

{

Console. writeline ("good figure, continue to maintain ");

}

Else

{

Console. writeline (" ~ Eat more in the future ");

}

}

}

Else

{

Console. writeline ("Friends, don't even know the gender? ");

}

Console. Readline ();

 

If () else () Statement in programming

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.