JAVA循环结构

一.while循环java

while(布尔表达式)spa

{code

//代码语句blog

}it

和C#一致for循环

 

二.do...while..循环class

do{循环

代码语句 }while(布尔表达式)遍历

在判断条件以前已经执行的代码语句,若是布尔表达式为true,则重复执行代码语句,直到布尔表达式为false.static

若是布尔表达式为false,则只执行一遍代码语句.

 

三.for 循环

for(初始条件;循环条件;状态改变)

{循环体,代码语句}

和C#一致

 

四.遍历(java加强for循环)

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("\n");
      String [] names ={"James", "Larry", "Tom", "Lacy"};
      for( String name : names ) {
         System.out.print( name );
         System.out.print(",");
      }
   }
}

输出结果:

10,20,30,40,50,

James,Larry,Tom,Lacy,

相关文章
相关标签/搜索