day03--if语句-格式1说明和使用
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.inmind.if01;
|
||||||
|
/*
|
||||||
|
if格式一:
|
||||||
|
|
||||||
|
if(判断条件){
|
||||||
|
语句;
|
||||||
|
}
|
||||||
|
|
||||||
|
执行顺序:先执行判断条件,判断条件必须是布尔型的结果,
|
||||||
|
如果为true,就执行大括号内部的语句,false就直接跳过大括号中的内容
|
||||||
|
*/
|
||||||
|
public class Demo01 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//判断下变量对应的值
|
||||||
|
int i = 11;
|
||||||
|
//判断变量i是否是指定的值,如果是则打印,否则就跳过不执行
|
||||||
|
if (i == 10) {
|
||||||
|
System.out.println("变量i的值是10");
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断2个值谁大
|
||||||
|
int a = 20;
|
||||||
|
int b = 30;
|
||||||
|
|
||||||
|
/*int max = a>b?a:b;*/
|
||||||
|
if (a > b) {
|
||||||
|
System.out.println("a的变量值大:"+a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b > a) {
|
||||||
|
System.out.println("b的变量值大:"+b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user