enter image description here 我需要一些if条件的帮助。我知道基本的工作原理:如果x == 1,返回一些东西。但是当我需要为不同的运营商定义特定的案例时,我该怎么做呢。如果运算符是+,那么结果表示总和。Java:如何为操作员编写条件?
所以基本上我需要将链接中的条件转换为recrsive方法的基本情况。我们了解到,我们总是使用如果为basecases。我知道如何以更小或更大的方式,但我不知道运营商。
enter image description here 我需要一些if条件的帮助。我知道基本的工作原理:如果x == 1,返回一些东西。但是当我需要为不同的运营商定义特定的案例时,我该怎么做呢。如果运算符是+,那么结果表示总和。Java:如何为操作员编写条件?
所以基本上我需要将链接中的条件转换为recrsive方法的基本情况。我们了解到,我们总是使用如果为basecases。我知道如何以更小或更大的方式,但我不知道运营商。
FYI:if()
不是一个循环while()
是。 if()
语句的工作原理为true或false,如果语句为true,则执行其他明智的某些其他代码。
例如:
if(1==1){// yourcode } // Always as true
// or
String hello="hi there";
if(hello.contains("hi there")){ // Your code which if the statement happen to be true }
else { // Not true}
int x=3, s=1, i=2;
if(x==(s+i)){ // Your code which if the statement happen to be true }
else { // Not true}
,你也可以找到很多的教程在网上帮您更好地了解所有的运营商!
你想说明它的正面还是负面?如果是的话,你会做以下...
if(x >= 0){ //this operator is saying if x is greater than or equal to 0
// you can remove the equal sign to have it just greater or
// switch it to less than.
//if positive
}else{
//all other numbers, which would just be negative numbers
}
我编辑了帖子并添加了一张照片 –
**“如果运营商为+那么结果表示的总和” ** - 我不明白你这个 – smoggers
的意思是如果循环不是Java中有效的控制流结构。 – Logan
请避免使用问题相关部分的链接。使信息成为问题的一部分(例如复制文本)。链接死了,并不是每个人都可以在某些环境中访问任何网址链接还有其他问题。 – Durandal