Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore อาร์เรย์

อาร์เรย์

Published by Sutarat Thongmai, 2022-01-28 03:45:10

Description: อาร์เรย์

Search

Read the Text Version

อาร์เรย์ (Array)

อาร์เรย์ คือแถวของตัวแปรชนิ ด เดียวกัน เปรียบได้กับ การนำกล่องหลายๆใบมา วางเรียงกันเป็นแถว ตัวแปรเปรียบเหมือนกล่อง

อาร์เรย์ของชนิ ดข้อมูลพื้นฐาน รู ปแบบ ชนิดข้อมูลพื้นฐาน[] อาร์เรย์ = {ค่าเริ่มต้น1, ค่าเริ่ม ต้น2, ... }; ตัวอย่าง int[] scores = {30, 50, 85};

การจองอาร์เรย์ รู ปแบบ อาร์เรย์ = new ชนิดข้อมูล[ขนาดของอาร์เรย์] ตัวอย่าง int[] scores; scores = new int[50];

วิธีในการสร้างอาร์เรย์ ประกาศ ให้ตัวแปรชื่อ scores เป็นอาร์เรย์ของ int int[] scores; จองพื้นที่ ใช้คำสั่ง new พร้อม กับระบุว่าต้องการจองพื้นที่เก็บ ตัวแปรกี่ตัว scores = new int[3];

วิธีในการสร้างอาร์เรย์ กำหนดค่า ตัวแปรแต่ละตัวใน อาร์เรย์ scores[0] = 30; scores[1] = 50; scores[2] = 85;


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook