zoukankan      html  css  js  c++  java
  • 我的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,输出括号里的内容到屏幕上

  • 相关阅读:
    Codeforces 992C(数学)
    Codeforces 990C (思维)
    Codeforces 989C (构造)
    POJ 1511 Invitation Cards(链式前向星,dij,反向建边)
    Codeforces 1335E2 Three Blocks Palindrome (hard version)(暴力)
    POJ 3273 Monthly Expense(二分)
    POJ 2566 Bound Found(尺取前缀和)
    POJ 1321 棋盘问题(dfs)
    HDU 1506 Largest Rectangle in a Histogram(单调栈)
    POJ 2823 Sliding Window(单调队列)
  • 原文地址:https://www.cnblogs.com/zeromyth/p/1472612.html
Copyright © 2011-2022 走看看