zoukankan      html  css  js  c++  java
  • java 循环控制

    while 循环

    while(condition){
           //xxx
    }
    


    for循环

    for(initialization;expression;update){//注意是分号的
        //xxxx
    }
    
    
          for(int x = 10; x < 20; x = x + 1) {
             System.out.print("value of x : " + x );
             System.out.print("
    ");
          }
    


    do{
        //xxxx
    }while(condition);
    
    int x = 10;
          do {
             System.out.print("value of x : " + x );
             x++;
             System.out.print("
    ");
          }while( x < 20 );
    
    
    


    循环控制声明
    break

    int [] numbers = {10, 20, 30, 40, 50};
    
          for(int x : numbers ) {
             if( x == 30 ) {
                break;
             }
             System.out.print( x );
             System.out.print("
    ");
          }
    

    continue

    int [] numbers = {10, 20, 30, 40, 50};
    
          for(int x : numbers ) {
             if( x == 30 ) {
                continue;
             }
             System.out.print( x );
             System.out.print("
    ");
          }
    

    java 循环增强

    for(declaration : expression) {
       // Statements
    }
    
    public class Test {
    
       public static void main(String args[]) {
          int [] numbers = {10, 20, 30, 40, 50};
    
          for(int x : numbers ) {
             System.out.print( x );
             System.out.print(",");
          }
          System.out.print("
    ");
          String [] names = {"James", "Larry", "Tom", "Lacy"}; //大括号
    
          for( String name : names ) {
             System.out.print( name );
             System.out.print(",");
          }
       }
    }
    

  • 相关阅读:
    iptables和DNS
    centos6.5下载
    linux 系统版本信息
    如何挂载
    Linux网络命令
    端口网络等
    linux安装tomcat
    ip设置
    最全DOS的CMD命令,程序员必会
    c语言文件分割与合并
  • 原文地址:https://www.cnblogs.com/cyany/p/9135383.html
Copyright © 2011-2022 走看看