我的第二个java程序 循环

public class Test {//类

    public Test (int num){//构造方法,和类同名,无返回值,接收传参并定义传参的类型,大小写敏感
     
    int x = 10;//局部变量,定义x为10,局部变量在方法外无效
      while( x < num ) {//x小于10,开始循环
         System.out.print("value of x : " + x );//打印x
         x++;//x加1递增
         System.out.print("\n");//打印换行
      }//循环结束

    }

   public static void main(String args[]) {//主方法,入口
      Test test = new Test(20);//创建一个类,并给类传参20
   }
}

 

posted @ 2015-11-22 11:26  fleam  阅读(179)  评论(0编辑  收藏  举报