2015-07-27

6109 단어 매일 자바
int farray[]=new int[3];//int specify the type of the element,[] indicate that 'farray' is an array
        //*********************************************************************************
        String [] stringArray=new String[3];//array can be also defined this way
        stringArray[0]="this is my reburn";//the elements which don't be assigned value manually will be null
        //****************************************************************
        int intArray[];
        intArray=new int[3];//this is another way to define an array:declare then assign space
        //**********************************************************************

        //***************************initialization********************************************
        int f2array[]={1,2,3};
        String [] string2Array={"string1","string2"};//initialize while declaring,this way is also known as static initailization

        int f3array[]=new int[5];
        f3array[0]=1;
        f3array[2]=4;//***************** it will be 0 where you didnot assign value
        Scanner s=new Scanner(System.in);//receive the data from console
        while(s.hasNext()){
            String line=s.nextLine();
            if (line.equals("exit")) {
                break;
            }
            if (line=="exit") {//cannot compare the content of two strings by '==',as for basic data type '==' will compare their values,but for complex the comparasion is address
                System.out.println("you choose to exit");
            }
            System.out.println(line=="exit");
        }
        for (int i=0;i<f3array.length ; i++) {
            System.out.println(f3array[i]);
        }
        String s1="hello";
        String s2="hello";
        System.out.println(s1.equals(s2));

    //*******************************constants in java*****************
    In Java,contants are declared by final keywords not const.
    System.out.println(NUM);

    //*********************************not changable string************cant change the data where string variables refer to*******
        String a="hello";
    //*****************************************build string*******************
    StringBuilder builder=new StringBuilder();
    String b="java";
    builder.append(a);
    builder.append(b);
    b=builder.toString();
    System.out.println(b);
    //*****************************************scanner*********
        System.out.println("what's your name?
"
); Scanner in=new Scanner(System.in); System.out.println("your name is "+in.nextInt()); //***************************************************console********** Console cons=System.console(); String username=cons.readLine("what's your name?"); char [] pwd=cons.readPassword("password:"); //****************************************formatting output******* double x=100000/3; System.out.printf("%0f",x); //**************************************************************

좋은 웹페이지 즐겨찾기