> if语句:
如果某个条件为true,则执行一系列语句。

语法:
//要执行的代码
>
}
program:
public class if {
public static void main(string[] args) {
float a =2.2f;
float b =5.4f;
if(b>a)
{
system.out.println(" b is greater than a");
}
}
}
output:
b is greater than a
> if-else语句:
在java中,if-else条件是一组规则或语句,如果条件为真,则执行一个代码块,如果条件为false,则执行另一个块。

语法:
} else {
//代码如果条件为false
}
**program**:
public class ifelse {
public static void main(string[] args) {
int n = 3;
if (n > 5) {
system.out.println("the number is greater than 5.");
}
else
{
system.out.println("the number is 5 or less.");
}
}
}
output:
the number is 5 or less.
else if语句: 如果第一个条件为false,则使用其他if语句使用其他if语句指定新条件。
>语法:
if(条件1){
//如果条件1为true
>
//如果条件1为false,并且条件2为true
>,则要执行的代码块
} else {
//如果条件1为false,并且条件2为false
,则要执行的代码块
}
**program:**
public class greater
{
public static void main (string args[])
{
int no1 = 1000;
int no2 = 1000;
if(no1>no2)
{
system.out.println("no1 is greater");
}
else if(no2>no1)
{
system.out.println("no2 is greater");
}
else
{
system.out.println("both are equal");
}
}
}
output:
both are equal
如果在java中,则嵌套 指另一个在另一个if语句中有一个if语句。如果外部条件为真,则将检查和执行内部条件。
如果 *
if(condition1){
if(condition3){ //语句; }
}
}
program:
public class nested if
{
public static void main(string args[])
{
int a = 10;
int b = 20;
// outer if condition
if (a == 10) {
// inner if condition
if (b != 20) {
system.out.println("geeksforgeeks");
}
else {
system.out.println("gfg");
}
}
}
}
任务:
程序:1
爪哇
public class age
{
public static void main (string args[])
{
int age1=25;
int age2=21;
if(age1
python
age1 = 25
age2 = 21
if age1 < age2:
print("the condition is false")
elif age2 < age1:
print("the condition is true")
output:
the condition is true
爪哇
program:2
public class if {
public static void main(string[] args) {
float a =2.2f;
float b =5.4f;
if(b>a)
{
system.out.println(" b is greater than a");
}
}
}
output:
b is greater than a
python
a = 2.2
b = 5.4
if b > a:
print("b is greater than a")
output:
num is greater than or equal 120
爪哇
program:3
public class greater
{
public static void main (string args[])
{
int no1 = 1000;
int no2 = 1000;
if(no1>no2)
{
system.out.println("no1 is greater");
}
else if(no2>no1)
{
system.out.println("no2 is greater");
}
else
{
system.out.println("both are equal");
}
}
}
output:
both are equal
python
no1 = 1000
no2 = 1000
if no1 > no2:
print("no1 is greater")
elif no2 > no1:
print("no2 is greater")
else:
print("Both are equal")
output:
Both are equal
>参考:
参考:
参考:
https://www.javatpoint.com/java-if-else










