ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Java assert

Java assert

原创 Linux操作系统 作者:staciy 时间:2010-07-01 07:39:14 0 删除 编辑

assert  logical_expresion;

assert  logical_expresion: string_expresion;

example:

if(daysInMonth == 30){

System.out.println("Month is April, June, September, or November");

} else if(daysInMonth == 31){

System.out.println("Month is January, March, May, July, August, October, or December.");

} else{

assert daysInMonth == 28 or daysInMonth == 29

System.out.println("Month is Februay");

}

else if(daysInMonth == 28 or daysInMonth == 29){

System.out.println("Month is February");

}else{

assert false;

//or assert false: "daysInMonth has the value" + daysInMonth;

}

Above two sections in different colur are two different ways to fullfill the same function else satement.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24123206/viewspace-666780/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: DB2_RR_TO_RS
请登录后发表评论 登录
全部评论

注册时间:2010-06-20

  • 博文量
    21
  • 访问量
    46069