乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      java基礎(chǔ)知識(shí)(四)

       豫龍晏子 2017-02-10

      java基礎(chǔ)知識(shí)(四)

      • 每天更新學(xué)習(xí)筆記,大家一起學(xué)習(xí)!

      • 不喜勿噴,謝謝!

      '數(shù)組和方法'的筆記

      1:數(shù)組

      • (1)數(shù)組:存儲(chǔ)同一種數(shù)據(jù)類型的多個(gè)元素的容器。

      • (2)特點(diǎn):每一個(gè)元素都有編號(hào),從0開始,最大編號(hào)是長度-1。

      編號(hào)的專業(yè)叫法:索引

      • (3)定義格式

      A:數(shù)據(jù)類型[] 數(shù)組名;

      B:數(shù)據(jù)類型 數(shù)組名[];

      • (4)數(shù)組的初始化

      A:動(dòng)態(tài)初始化

      只給長度,系統(tǒng)給出默認(rèn)值

      舉例:int[] arr = new int[3];

      B:靜態(tài)初始化

      給出值,系統(tǒng)決定長度

      舉例:int[] arr = new int[]{1,2,3};

      簡化版:int[] arr = {1,2,3};

      • (5)Java的內(nèi)存分配

      A:棧 存儲(chǔ)局部變量

      B:堆 存儲(chǔ)所有new出來的

      C:方法區(qū)(面向?qū)ο蟛糠?

      D:本地方法區(qū)(系統(tǒng)相關(guān))

      E:寄存器(CPU使用)

      • 注意:

      a:局部變量 在方法定義中或者方法聲明上定義的變量。

      b:棧內(nèi)存和堆內(nèi)存的區(qū)別

      棧:數(shù)據(jù)使用完畢,就消失。

      堆:每一個(gè)new出來的東西都有地址

      每一個(gè)變量都有默認(rèn)值

      byte,short,int,long : 0

      float,double : 0.0

      char : '\u0000'

      boolean: false

      引用類型 : null

      數(shù)據(jù)使用完畢后,在垃圾回收器空閑的時(shí)候回收。

      • (6)數(shù)組的常見操作

      • A:遍歷

      方式1:

      1. public static void printArray(int[] arr) {

      2. for(int x=0; x

      3. System.out.println(arr[x]);

      4. }

      5. }

      方式2:

      1. public static void printArray(int[] arr) {

      2. System.out.print('[');

      3. for(int x=0; x

      4. if(x == arr.length-1) {

      5. System.out.println(arr[x]+']');

      6. }else {

      7. System.out.println(arr[x]+', ');

      8. }

      9. }

      10. }

      • B:最值

      最大值:

      1. public static int getMax(int[] arr) {

      2. int max = arr[0];

      3. for(int x=1; x

      4. if(arr[x] > max) {

      5. max = arr[x];

      6. }

      7. }

      8. return max;

      9. }

      最小值:

      1. public static int getMin(int[] arr) {

      2. int min = arr[0];

      3. for(int x=1; x

      4. if(arr[x] < min)="">

      5. min = arr[x];

      6. }

      7. }

      8. return min;

      9. }

      • C:逆序

      方式1:

      1. public static void reverse(int[] arr) {

      2. for(int x=0; x

      3. int temp = arr[x];

      4. arr[x] = arr[arr.length-1-x];

      5. arr[arr.length-1-x] = temp;

      6. }

      7. }

      方式2:

      1. public static void reverse(int[] arr) {

      2. for(int start=0,end=arr.length-1; start<=end; start++,end--)="">

      3. int temp = arr[start];

      4. arr[start] = arr[end];

      5. arr[end] = temp;

      6. }

      7. }

      • D:查表

      1. public static String getString(String[] strArray,int index) {

      2. return strArray[index];

      3. }

      • E:基本查找

      方式1:

      1. public static int getIndex(int[] arr,int value) {

      2. for(int x=0; x

      3. if(arr[x] == value) {

      4. return x;

      5. }

      6. }

      7. return -1;

      8. }

      方式2:

      1. public static int getIndex(int[] arr,int value) {

      2. int index = -1;

      3. for(int x=0; x

      4. if(arr[x] == value) {

      5. index = x;

      6. break;

      7. }

      8. }

      9. return index;

      10. }

      2:方法

      • (1)方法就是完成特定功能的代碼塊。

      注意:在很多語言里面有函數(shù)的定義,而在Java中,函數(shù)被稱為方法。

      • (2)格式

      修飾符 返回值類型 方法名(參數(shù)類型 參數(shù)名1,參數(shù)類型 參數(shù)名2...) {

      方法體語句;

      return 返回值;

      }

      修飾符:目前就用 public static。

      返回值類型:就是功能結(jié)果的數(shù)據(jù)類型

      方法名:就是起了一個(gè)名字,方便我們調(diào)用該方法。

      參數(shù)類型:就是參數(shù)的數(shù)據(jù)類型

      參數(shù)名:就是變量

      參數(shù)分類:

      實(shí)參:實(shí)際參與運(yùn)算的數(shù)據(jù)

      形參:方法上定義的,用于接收實(shí)際參數(shù)的變量

      方法體語句:就是完成功能的代碼塊

      return:結(jié)束方法

      返回值:就是功能的結(jié)果,由return帶給調(diào)用者。

      • (3)兩個(gè)明確:

      返回值類型:結(jié)果的數(shù)據(jù)類型

      參數(shù)列表:參數(shù)的個(gè)數(shù)及對應(yīng)的數(shù)據(jù)類型

      • (4)方法調(diào)用

      A:有明確返回值的方法

      a:單獨(dú)調(diào)用,沒有意義

      b:輸出調(diào)用,不是很好,因?yàn)槲铱赡苄枰唤Y(jié)果進(jìn)行進(jìn)一步的操作。但是講課一般我就用了。

      c:賦值調(diào)用,推薦方案

      B:void類型修飾的方法

      a:單獨(dú)調(diào)用

      • (5)方法的注意事項(xiàng)

      A:方法不調(diào)用不執(zhí)行

      B:方法之間是平級關(guān)系,不能嵌套定義

      C:方法定義的時(shí)候,參數(shù)是用,隔開的

      D:方法在調(diào)用的時(shí)候,不用在傳遞數(shù)據(jù)類型

      E:如果方法有明確的返回值類型,就必須有return語句返回。

      • (6)方法重載

      在同一個(gè)類中,方法名相同,參數(shù)列表不同。與返回值無關(guān)。

      參數(shù)列表不同:

      參數(shù)的個(gè)數(shù)不同。

      參數(shù)的對應(yīng)的數(shù)據(jù)類型不同。

      (8)方法重載案例

      不同的類型的多個(gè)同名方法的比較。

      • (7)案例:

      1. 輸出m行n列的星形

      java基礎(chǔ)知識(shí)(四)


      2:獲取兩個(gè)數(shù)中的較大值

      java基礎(chǔ)知識(shí)(四)

      3:獲取三個(gè)數(shù)中的最大值

      直接在main方法里調(diào)用下圖getMax(, , ,),就可以比較出最大值;


      java基礎(chǔ)知識(shí)(四)


      4:輸出nn乘法表

      java基礎(chǔ)知識(shí)(四)

      這里提供的只是曾經(jīng)學(xué)習(xí)整理的筆記,勿噴,謝謝,僅供java愛好者參考!

      每日更新,請大家多多關(guān)注.謝謝!!!

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多