条件语句if语句 [英] Conditional statements if statements
本文介绍了条件语句if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
条件声明如果i大于或等于j输出result1。如果我小于j输出结果值2的两倍。
我尝试过:
Conditional statement that if i is greater than or equal to j output result1. if i is less than two times the value of j output result2.
What I have tried:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
string output = "";
const string result1 = "Foo";
const string result2 = "Bar";
int i = 100;
int j = 100;
if (i>=j)
{
output = result1 + result2 ;
}
if (i<(2*j))
{
output = result2;
}
Console.Write(output);
}
}
}
推荐答案
你需要考虑的是你到底是什么试图这样做:
What you need to think about is exactly what you are trying to do:
If i is greater than or equal to j output result1. Otherwise, if i is less than two times the value of j output result2.
那么你需要编码的是:
So what you need to code is just that:
const string result1 = "Foo";
const string result2 = "Bar";
int i = 100;
int j = 100;
string output = "";
if (i >= j)
{
output = result1;
}
else if (i < (2 * j))
{
output = result2;
}
Console.Write(output);
这篇关于条件语句if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文