初识Java

JAVA:

1、布尔变量boolean(bool)

2、final float aFinalVar=3.1415926(#define aVar 3.1415926)

3、一元运算符:前缀 operator op;

         后缀 op operator;

  二元运算符:中缀 op1 operator op2

  三元运算符:op1 ? op2 : op3  相当于 if-else 语句:如果 op1 为ture,则返回op2,否则返回op3;

4、

  a.输入流: 

    a.1  控制台接收一个字符,但这只能输入一个char类型字符,不能输入数字之类的

      eg:public static void main(String[] args) throws IOException{
          // TODO Auto-generated method stub
          System.out.print("输入字符");
          char str=(char)System.in.read();
          System.out.print(str);
       }

    a.2  控制台接收一个字符串

      eg:public static void main(String[] args) throws IOException{
          // TODO Auto-generated method stub
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          String str=null;
          str=br.readLine();
          System.out.print(str);
       }

      a.3 引入类 import java.util.*;  创建输入的对象 

      eg:

          Scanner reader = new Scanner(System.in);  

          String name=reader.next();

  b.输出流: java:System.out.println("X="+var); C:printf("%s,str")   C++:cout<<"X="<<var<<endl;

5、变量运算:

  int + double 为 double;

6、对于10.0/0.0(都为double类型时) java认为它是合法的,结果为无穷大(Infinity)  0.0/0.0 结果为无定义(NaN)

7、string 和new string ; int 和 new Integer; ==和equal();

  String类是字符串常量,是不可更改的常量。而StringBuffer是字符串变量,它的对象是可以扩充和修改的。

  String.charAt(int):返回String中的第i哥元素,但是Stirng类型没有下标;       

8、数组:

    声明:

       float[] arryOfFloat=new float[10] 或者 float arrryOfFloat[]=new float[10];

       anArry=new int[10];  //获取数组长度用length而不是length()。在这里,length是所有数组都具备的属性,而不是方法。

    创建并初始化:

        boolean[] answer={0,1,1,0};

        String[] str={"You","are","abnormality"};

9、instanceof 运算符

  op1(对象名) instanceof op2(类名);   判断op1是否是op2的对象实例

10、跳转语句

  break;continue;lable;return;

  a),continue test;

  b),break test;

 

posted on 2015-04-15 20:53  I'm龙龙  阅读(133)  评论(0)    收藏  举报

导航