• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Myth's space
好好学习,不见进步
博客园    首页    新随笔    联系   管理    订阅  订阅

我的JAVA之旅(二)初识JAVA

      三年后《Thinking》里的文字依旧晦涩难懂。看完前几章节,只觉得对这种以绕口令的方式书写理解起来还是颇为费力。费力归费力,但也总算有了一点收获。了解了JAVA和C/C++的区别,了解了JAVA的一些名词,比如对象(Object),封装(encapsulation),继承(Inheritance)。。等。

      相比起来,《Thinking》里的文字还是过于理论,幸好手边还有一本《JAVA参考大全》,也许边看程式边看《Thinking》效果会更好一些呢!

      在翻看了JAVA的一些基础的类库和数据类型之后,参考了一些范例。开始书写我的第一个程式,熟悉JAVA的工作原理,熟悉 eclpise的使用。

The first program.

code:


public class Example{
public static void main(String gac2[])
{
 int x,y;
 y=20;
 for(x=0;x<10;x++){
  System.out.println("The value of X is "+x);
  System.out.println("The value of Y is "+y);
  y=y-2;
 }
}
}

---------------------------------

The value of X is 0
The value of Y is 20
The value of X is 1
The value of Y is 18
The value of X is 2
The value of Y is 16
The value of X is 3
The value of Y is 14
The value of X is 4
The value of Y is 12
The value of X is 5
The value of Y is 10
The value of X is 6
The value of Y is 8
The value of X is 7
The value of Y is 6
The value of X is 8
The value of Y is 4
The value of X is 9
The value of Y is 2

eclpise里按ctrl+s保存会自动编译。就如同dos下运行javac一样。

就像 helloworld一样,这段代码定义了一个公共类Example,主函数main里申明了一个空数组,定义两个整形变量x,y,病对y赋值,循环里调用了基类System里的换行方法println,输出括号里的内容到屏幕上

 

 

posted @ 2009-05-20 22:07  Mr.Myth  阅读(205)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3