انتقل إلى المحتوى
أمين أبوزيد
BEG-015

المصفوفات والنصوص

  • 8 درس
  • 84 دقيقة قراءة
  • 5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • المصفوفات أحادية/متعددة الأبعاد
  • String
  • StringBuilder
  • العمليات الشائعة

تعلّم أولًا

84 دقيقة قراءة · 5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Create, fill, iterate, and copy one- and two-dimensional arrays.
  2. Use common String methods (length, charAt, substring, indexOf, split, equals, trim, toUpperCase).
  3. Explain string immutability and use StringBuilder for repeated concatenation.
  4. Avoid ArrayIndexOutOfBoundsException by reasoning about valid indices.

الدروس

  1. 01المصفوفات: قوائم ثابتة الحجم10 د قراءة
  2. 02التكرار على العناصر وfor المحسّنة11 د قراءة
  3. 03المصفوفات ثنائية الأبعاد10 د قراءة
  4. 04التعامل مع Strings10 د قراءة
  5. 05عدم القابلية للتغيير (Immutability) وStringBuilder11 د قراءة
  6. 06الفئة المساعدة Arrays10 د قراءة
  7. 07عرض عملي: مدير درجات الطلاب باستخدام المصفوفات11 د قراءة
  8. 08عرض عملي: أخطاء النصوص: == والإزاحة بواحد والتجميع البطيء11 د قراءة

المختبر والتمارين

Lab

BEG-015-LAB1 · Student-grade manager (mini-project 3 of 3)

Outcomes: 1–4 · Time: ~3 h

  1. Store student names and grades in arrays (read them or start with sample data).
  2. Compute the average, highest, and lowest grade, and a letter grade for each student.
  3. Search a student by name (ignore case) and show the grade, or "not found".
  4. Print an aligned report.
  5. Handle an empty class without crashing.

Acceptance: correct statistics; case-insensitive search; handles empty class.

Exercises (assessment: seven exercises plus the grade manager)

IDOutcomeTask
BEG-015-EX011Create an int[] of 5 numbers, fill it with a loop, print it with Arrays.toString, and make a real copy.
BEG-015-EX021Create a 3x3 int[][] and print its diagonal and the sum of all cells.
BEG-015-EX032Given " Hello, World ": trim it, get its length, the index of "World", and the substring "Hello".
BEG-015-EX042Split "ana,bob,carl" and print each name in upper case.
BEG-015-EX053Explain why s.toUpperCase(); alone does not change s.
BEG-015-EX063Build the string "1,2,3,...,1000" with StringBuilder and explain why not +=.
BEG-015-EX074List the valid indices for new int[4]; fix a loop with i <= arr.length.
أظهر الحلول
  • EX01 int[] a = new int[5]; for (int i = 0; i < a.length; i++) a[i] = i * 2; int[] b = Arrays.copyOf(a, a.length); (b = a would not be a copy).
  • EX02 Diagonal g[i][i]; sum with two nested loops over g.length and g[r].length.
  • EX03 t = s.trim() gives "Hello, World"; length 12; t.indexOf("World") is 7; t.substring(0, 5) is "Hello".
  • EX04 for (String n : "ana,bob,carl".split(",")) System.out.println(n.toUpperCase());
  • EX05 Strings are immutable; the method returns a new String that must be assigned: s = s.toUpperCase();.
  • EX06 StringBuilder sb; for (i = 1..1000) { if (i > 1) sb.append(','); sb.append(i); } — += copies the whole string each time.
  • EX07 Valid indices are 0, 1, 2, 3. Change <= to <.
  • Outcome 4 is also tested in the lab (empty class) and quiz.

الاختبار

Outcomes: O1 arrays · O2 String methods · O3 immutability and StringBuilder · O4 valid indices.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1The first index of an array is:O1
  2. 2new int[5] creates an array whose elements start as:O1
  3. 3grid[2][3] in a 2D array means:O1
  4. 4To compare two Strings' text, use:O2
  5. 5"hello".substring(1, 3) is:O2
  6. 6indexOf returns what when the text is missing?O2
  7. 7Strings are immutable. So s.toUpperCase(); alone:O3
  8. 8For repeated concatenation in a loop, use:O3
  9. 9For an array of length 5, the last valid index is:O4
  10. 10arr[arr.length] causes:O4

الجزء العملي

Seven exercises BEG-015-EX01 to EX07 plus the student-grade manager. Pass: at least six exercises correct and a grade manager with correct statistics, case-insensitive search, and empty-class handling.

أخطاء شائعة

Comparing strings with ==; off-by-one on length; concatenating in loops.

التقييم

7 exercises plus the grade manager.

الصلة بالمسار الوظيفي

Arrays underpin collections (BEG-030) and data structures (BEG-040).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.