03.分支语句

  • 分支语句

 

  • if..else...结构(一)
 
  1. publicclassTestIf{
  2. publicstaticvoid main(String args []){
  3. int i =6;
  4. if(i >5&& i <10){
  5. System.out.println("i的值大于5,小于10");
  6. }
  7. }
  8. }
 
  • if...else...结构(二)
 
  1. publicclassTestIf{
  2. publicstaticvoid main(String args []){
  3. int i =5;
  4. if(i <10){
  5. System.out.println("i的值小于10");
  6. }
  7. else{
  8. System.out.println("i的值大于或等于10");
  9. }
  10. }
 
  • if...else...结构(三)
    • 如果第一个为真,后面的全部略过;如果为假,这则判断第二个。
  1. publicclassTestIf{
  2. publicstaticvoid main(String args []){
  3. int i =-1;
  4. if(i <0){
  5. System.out.println("i为负数");
  6. }
  7. elseif(i++>0){
  8. System.out.println("i为正数");
  9. }
  10. else{
  11. System.out.println("i为0");
  12. }
  13. System.out.println(i);
  14. }
  15. }
 
  • Switch结构
    • 表达式只允许:char,比特型,短整型,整型。
  1. publicclassTestSwitch{
  2. publicstaticvoid main(String args[]){
  3. char c ='a';
  4. switch(c){
  5. case'b':
  6. System.out.println('b');
  7. break;
  8. case'd':
  9. System.out.println('d');
  10. break;
  11. case'a':
  12. System.out.println('a');
  13. break;
  14. default:
  15. System.out.println('s');
  16. }
  17. }
  18. }
 
 





转载于:https://www.cnblogs.com/arroneve/p/5815371.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值