SlideShare a Scribd company logo
Array 1  มิติ
Array 1  มิติ 51 51 63 97 24
Array 1  มิติ int score; 51 51 63 97 24
Array 1  มิติ int score; int score[] = new int[4]; 51 51 63 97 24
Array 1  มิติ int score[] = new int[4]; [0]  [1]  [2]  [3] score[0] = 51 score[1] =  ?? score[2] =  ?? score[3] =  ?? 51 63 97 24
Array 1  มิติ :  การประกาศตัวแปร int s[] = new int[4]; String s[] = new String[4]; float s[] = new float[4]; int s[]; s = new int[4];
Array 1  มิติ :  การให้ค่าตัวแปร int s[] = new int[4]; s[0] = 10;  s[2] = 30; s[1] = 20;  s[3] = 40; int s[] = {10, 20, 30, 40} [0]  [1]  [2]  [3] 10 20 30 40
Array 1  มิติ ให้นักศึกษาสร้าง  class  ขึ้นมาใหม่ ให้ชื่อว่า  TestArray1 เพื่อใช้เก็บคะแนนของนักศึกษา และให้ทำการรับค่า  int  จำนวน  1  ค่า เพื่อนำไปกำหนดขนาดของจำนวน นศ .
Array 1  มิติ public static void main(String[] args){ ... รับค่า  int 1 ค่า  (num)... int score[] = new int[ num ]; } ถ้าต้องการรู้ขนาดของ  Array ให้ใช้  score .length
Array 1  มิติ public static void main(String[] args){ ... รับค่า  int 1 ค่า  (num)... int score[] = new int[ num ]; ... ให้รับคะแนนของ นศ .  ตามจำนวน  num  โดยใช้  For Loop ... } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
Array 1  มิติ public static void main(String[] args){ ... รับค่า  int 1 ค่า  (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ ... รับค่าใส่ในแต่ละช่อง ... } } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
Array 1  มิติ public static void main(String[] args){ ... รับค่า  int 1 ค่า  (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ System.out.print(“Enter score[”+  s  + “]: ”); score[s]  = scan.nextInt(); } } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
Array 1  มิติ public static void main(String[] args){ ... รับค่า  int 1 ค่า  (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ System.out.print(“Enter score[”+ s + “]:”); score[s]  = scan.nextInt(); } ...  แสดงค่าที่รับออกมา ... } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[2]: 30 Enter score[3]: 40 Score are:  10 20 30 40
Array 1  มิติ String  output  = “ ”; for(int p=0;p<score.length;p++){ output  =  output  +  score[p]  + “  ”; } System.out.println(“Score are”+ output ); Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[2]: 30 Enter score[3]: 40 Score are:  10 20 30 40
Array 1  มิติ ให้ เปลี่ยน การรับค่าคะแนนจาก  Keyboard  เป็นการ  Random  คะแนนระหว่าง  1-100 โดยสร้างเป็น  Method  ขึ้นมาให้ชื่อว่า  rnd  และเรียกใช้ผ่าน  Method  นี้ -------------------------------------------- public static int  rnd (int st, int ed){ ...  return ...; }   score[s]  =  rnd (1, 100);
Array 1  มิติ String  output  = “ ”; for(int p=0;p<score.length;p++){ output  =  output  +  score[p]  + “  ”; } System.out.println(“Score are”+ output ); ให้เปลี่ยนเป็น  Method  แบบ  Recursive

More Related Content

PDF
662305 LAB13
PDF
Applet 5 class_inheritance
PDF
Applet 7 image_j_panel
PDF
New Assingment3 array2D
PDF
Applet 6 mouse_keyboard
PDF
Applet 7 image_j_panel
PDF
Applet 5 class_inheritance
PDF
วิธีการกำหนดสิทธิให้กับ Directory
662305 LAB13
Applet 5 class_inheritance
Applet 7 image_j_panel
New Assingment3 array2D
Applet 6 mouse_keyboard
Applet 7 image_j_panel
Applet 5 class_inheritance
วิธีการกำหนดสิทธิให้กับ Directory

More from Nitigan Nakjuatong (17)

PDF
662305 LAB12
PDF
Applet 4 class_composition
PDF
PDF
PDF
PDF
Applet 3 design_class_composition
PDF
PDF
Applet 2 container and action_listener
PDF
662305 Lab7new
PDF
Assingment3 array2 d
PDF
PPT
PPT
Method part2
PPT
Control structure
PPT
Method JAVA
PPT
Set putty to use numeric keyboard in pico
PDF
Putty basic setting
662305 LAB12
Applet 4 class_composition
Applet 3 design_class_composition
Applet 2 container and action_listener
662305 Lab7new
Assingment3 array2 d
Method part2
Control structure
Method JAVA
Set putty to use numeric keyboard in pico
Putty basic setting
Ad

Array

  • 1. Array 1 มิติ
  • 2. Array 1 มิติ 51 51 63 97 24
  • 3. Array 1 มิติ int score; 51 51 63 97 24
  • 4. Array 1 มิติ int score; int score[] = new int[4]; 51 51 63 97 24
  • 5. Array 1 มิติ int score[] = new int[4]; [0] [1] [2] [3] score[0] = 51 score[1] = ?? score[2] = ?? score[3] = ?? 51 63 97 24
  • 6. Array 1 มิติ : การประกาศตัวแปร int s[] = new int[4]; String s[] = new String[4]; float s[] = new float[4]; int s[]; s = new int[4];
  • 7. Array 1 มิติ : การให้ค่าตัวแปร int s[] = new int[4]; s[0] = 10; s[2] = 30; s[1] = 20; s[3] = 40; int s[] = {10, 20, 30, 40} [0] [1] [2] [3] 10 20 30 40
  • 8. Array 1 มิติ ให้นักศึกษาสร้าง class ขึ้นมาใหม่ ให้ชื่อว่า TestArray1 เพื่อใช้เก็บคะแนนของนักศึกษา และให้ทำการรับค่า int จำนวน 1 ค่า เพื่อนำไปกำหนดขนาดของจำนวน นศ .
  • 9. Array 1 มิติ public static void main(String[] args){ ... รับค่า int 1 ค่า (num)... int score[] = new int[ num ]; } ถ้าต้องการรู้ขนาดของ Array ให้ใช้ score .length
  • 10. Array 1 มิติ public static void main(String[] args){ ... รับค่า int 1 ค่า (num)... int score[] = new int[ num ]; ... ให้รับคะแนนของ นศ . ตามจำนวน num โดยใช้ For Loop ... } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
  • 11. Array 1 มิติ public static void main(String[] args){ ... รับค่า int 1 ค่า (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ ... รับค่าใส่ในแต่ละช่อง ... } } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
  • 12. Array 1 มิติ public static void main(String[] args){ ... รับค่า int 1 ค่า (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ System.out.print(“Enter score[”+ s + “]: ”); score[s] = scan.nextInt(); } } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[3]: 30 Enter score[4]: 40
  • 13. Array 1 มิติ public static void main(String[] args){ ... รับค่า int 1 ค่า (num)... int score[] = new int[ num ]; for(int s=0;s< score.length ;s++){ System.out.print(“Enter score[”+ s + “]:”); score[s] = scan.nextInt(); } ... แสดงค่าที่รับออกมา ... } Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[2]: 30 Enter score[3]: 40 Score are: 10 20 30 40
  • 14. Array 1 มิติ String output = “ ”; for(int p=0;p<score.length;p++){ output = output + score[p] + “ ”; } System.out.println(“Score are”+ output ); Enter num of Student: 4 Enter score[0]: 10 Enter score[1]: 20 Enter score[2]: 30 Enter score[3]: 40 Score are: 10 20 30 40
  • 15. Array 1 มิติ ให้ เปลี่ยน การรับค่าคะแนนจาก Keyboard เป็นการ Random คะแนนระหว่าง 1-100 โดยสร้างเป็น Method ขึ้นมาให้ชื่อว่า rnd และเรียกใช้ผ่าน Method นี้ -------------------------------------------- public static int rnd (int st, int ed){ ... return ...; } score[s] = rnd (1, 100);
  • 16. Array 1 มิติ String output = “ ”; for(int p=0;p<score.length;p++){ output = output + score[p] + “ ”; } System.out.println(“Score are”+ output ); ให้เปลี่ยนเป็น Method แบบ Recursive