zoukankan      html  css  js  c++  java
  • Java入门 之 流程控制语句

    01. Java条件语句之 if

      

    02. Java条件语句之 if...else

      

    03. Java条件语句之 多重if

      

    04. Java条件语句之 嵌套if

      

    05. Java条件语句之 switch

      

    06. Java循环语句之 while:先判断,后执行

      

    07. Java循环语句之 do...while:先执行,后判断(至少执行一次)

      

    08. Java循环语句之 for

    package imooc;
    
    public class practice {
    	public static void main(String[] args) {
    		//normal test
    		for (int a=1; a<=5; a++) {
    			System.out.println("a");
    		}
    		
    		//omit initialization of variable
    		int b=1;
    		for ( ; b<=5; b++) {
    			System.out.println("b");
    		}
    		
    		//omit condition -> endless loop
    		//for (int c=1;  ; c++) {
    		//	System.out.println("c");
    		//}
    		
    		//omit changing of variable
    		for (int d=1; d<=5; ) {
    			System.out.println("d");
    			d++;
    		}
    		
    		//multiple variables
    		for (int e=1,f=2; e<=5; e++,f--) {
    			System.out.println(e+"+"+f+"="+(e+f));
    		}
    	}
    
    }

    09. Java循环跳转语句之 break:退出指定循环

      

    10. Java循环跳转语句之 continue:跳过循环体中剩余语句,执行下一次循环

      

    11. Java循环语句之 多重循环

    package imooc;
    
    public class practice {
    	public static void main(String[] args) {
    		System.out.println("right triangle");
    		for(int i=1; i<=3; i++) {
    			for(int j=1; j<=i; j++) {
    				System.out.print("*");
    			}
    			System.out.println();
    		}
    	}
    
    }

     12. Practice:Judge digits

    package imooc;
    
    public class practice {
    	public static void main(String[] args) {
    		int num = 999;
    		int count=1;
    		for (count=1; (num/=10)!=0; count++);
    
    		System.out.println(count);
    	}
    }
  • 相关阅读:
    cocos2d-x3.x Vector
    CC_CALLBACK之间的区别
    android平台菜单返回键监听
    更方便的函数回调——Lambda
    MySQL 多实例启动和关闭脚本
    ERROR 23 (HY000) at line 29963: Out of resources when opening file
    [ERROR] Failed to open log
    ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)
    show engine innodb statusG
    【转载】mysql 四种隔离级别分析
  • 原文地址:https://www.cnblogs.com/wnzhong/p/7716312.html
Copyright © 2011-2022 走看看