Java条件语句
1:if—else
代码部分
public class Text
{
//定义静态方法
public static void Mdin(string Ars[])
{
//定义一个参数
int A=20;
if(x<10)
{
System.out.print("这是 if 语句");
}
else
{
System.out.print("这是 else 语句");
}
}
}
运行结果
这是else语句
2:if—else if----else
public class Test {
public static void main(String args[]){
int x = 30;
if( x == 10 ){
System.out.print("Value of X is 10");
}else if( x == 20 ){
System.out.print("Value of X is 20");
}else if( x == 30 ){
System.out.print("Value of X is 30");
}else{
System.out.print("这是 else 语句");
}
}
}
运行结果
Value of X is 30