java新手筆記2

來源:互聯網
上載者:User

標籤:

1.注釋

/**  doc注釋*    類說明資訊*///聲明類  檔案名稱與類名一致public class World {//類定界符//聲明方法 main方法    public static void main(String[] args) {         System.out.println("World World!");         //System.out.println("welcome java world!");         //注釋的代碼不執行  單行注釋      /*  多行注釋      System.out.println("World World!");      System.out.println("World World!");      System.out.println("World World!");      System.out.println("World World!");      */    }}

 2.變數

public class InputDemo {    public static void main(String[] args) {      //輸出       System.out.println("TR21" );      System.out.print("javase\n");      System.out.printf("%-5d%d  %.5f\n",15,3,3.14);      System.out.println("\"大家好\" xml\toracle j\bavase");      int a ;//聲明變數      a = 20;//賦值      int b = 10;      a = a + b;      System.out.println("a = " + a);//變數不能同名      final double PI = 3.14;//常量 final      //PI = 3.15;      System.out.println("PI = " + PI);    }}

 3.資料類型

public class DataDemo {    public static void main(String[] args) {       //System.out.println("Hello...");       int _a3 = 10;       //整型  byte short int  long       int a = -5;//3.14;       System.out.println(Integer.MAX_VALUE);       short b = 20;       System.out.println(Short.MAX_VALUE);       long c = 123;      System.out.println(Long.MAX_VALUE);      byte d = 127;      System.out.println("d = " + d);      //d = 128;      c = 1234567890123456L;//預設整型 轉換long類型      //浮點型      float f = 3.14f;//預設double      double dou = 3.14;      System.out.println("f = " + f);      System.out.println("dou = " + dou);      char ch = ‘A‘;      System.out.println("ch = " + ch);      ch = ‘中‘;//變數賦值      System.out.println("ch = " + ch);      boolean boo = true;//false      int num1 = 123;      int num8 = 010;      int num16 = 0xa;      System.out.println("num1 = " + num1);      System.out.println("num8 = " + num8);      System.out.println("num16 = " + num16);    }   }

 4.資料類型轉換

public class DataConvert {    public static void main(String[] args) {             int a = 10;       long b = a;//隱式類型轉換  低精度--》高精度       byte c = (byte)b;//強制類型轉換             System.out.println("a = " + a);      System.out.println("b = " + b);      System.out.println("c = " + c);      long result = c + b + a;      System.out.println("result = " +  result);// long          }}

 

java新手筆記2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.