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