黑马程序员技术交流社区
标题:
if语法
[打印本页]
作者:
fenger7
时间:
2015-10-21 18:30
标题:
if语法
//
public class IfDemo
{
public static void main(String[] args)
{
int i=1;
// simple if
if(i<10)
System.out.println("i<10");
if(i>10)
System.out.println("i>0");
//if using ablock of code
if(i==1)
{
System.out.println("i equals 1");
System.out.println("Use a code block to");
System.out.println("excute more than 1 statement");
}
//if-else
if(i==2)
System.out.println("i equals 2");
else
{
//a block contains multiple statements
System.out.println("i dose not equal 2");
System.out.println("we can execute more");
System.out.println("than one statement in");
System.out.println("an if");
}
//compound logical expressions
if(i==1||i==2)
System.out.println("i equals 1 or 2");
if(i>0&&i<3)
System.out.println("i is >0 and <3");
//nested if can replace compound logical expressions
if(i>0)
if(i<3)
System.out.println("i is >0 and <3");
//comditional operator
int j=(i==1)?5:6;
System.out.println("i equals "+i);
}
}
作者:
ppaapc
时间:
2015-10-21 20:32
好无聊啊
作者:
C威
时间:
2015-10-21 21:02
先这么多废话干啥0.0
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2