
Array Patterns Exploration in CSE 121 Class
Dive into the intricacies of array patterns, resizing arrays, combining arrays, and more in this comprehensive guide from the CSE 121 lesson. Learn about 2D array patterns, declaring arrays of multiple data types, counting elements meeting conditions, modifying array elements, and searching for specific elements. Get ready to enhance your array manipulation skills!
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CSE 121 Lesson 16: Array Patterns Matt Wang & Brett Wortzman Autumn 2024 Abby Afifah Ailsa Alice Aliyan Arohan Chlo Christopher Dalton Derek Elizabeth Ethan TAs: Hanna Hannah Heather Hibbah Janvi Jasmine Judy Julia Kelsey Lucas Luke Mahima Maitreyi Maria Merav Minh Neha Ronald Ruslana Sahej Sam Samrutha Sushma Vivian sli.do #cse121 Today s playlist: 121 24au lecture tunes Yijia Zachary
Announcements & Reminders C3 due tonight (Wednesday, November 20) at 11:59pm Quiz 2 in section tomorrow (Thursday, November 21) Final Exam: Wednesday, December 11, 12:30pm-2:20pm More details on Friday Lesson 17 - Winter 2024 2
(PCM) Your Questions on Arrays! Do all array problems follow the similar base pattern as the one's provided in the previous slide? How do you resize an array when you need to add elements? Is there an easy way to combine two arrays that were created previously into a new array in a specific unknown order? Lesson 17 - Winter 2024 3
(PCM) Your Questions on Arrays! How are 2D array patterns different from 1D array patterns? Could I declare an array of multiple data types using the Object[] class? Can arrays of arrays have arrays? Lesson 17 - Winter 2024 4
(PCM) Counting Elements that Meet a Condition "one" "two" "three" "six" "seven" "eight" "ten" public static int evenLength(String[] list) { int countEven = 0; for (int i = 0; i < list.length; i++) { if ( ) { countEven++; } } return countEven; } Lesson 17 - Winter 2024 5
(PCM) Modifying Elements of an Array 4 8 15 16 23 42 public static void clamp(int min, int max, int[] list) { for (int i = 0; i < list.length; i++) { if ( > max) { = max; } else if ( < min) { = min; } } } Lesson 17 - Winter 2024 6
(PCM) Searching for an Element "one" "two" "three" "six" "seven" "eight" "ten" public static int indexOfIgnoreCase(String phrase, String[] list) { for (int i = 0; i < list.length; i++) { if ( ) { return ; } } return ; } Lesson 17 - Winter 2024 7
(PCM) Shifting Elements 9.6 -88.0 4.815 0.009 7.0184 42.9 public static void rotateRight(double[] list) { double lastElement = list[list.length - 1]; for (int i = list.length - 1; i > 0; i--) { list[i] = list[i - 1]; } } Lesson 17 - Winter 2024 8
(PCM) Looking at Multiple Elements in an Array 0 1 9 1 0 public static boolean isPalindrome(int[] list) { for (int i = 0; i < list.length / 2; i++) { if (list[i] != list[list.length - 1 - i]) { return ; } } return ; } Lesson 17 - Winter 2024 9
(PCM) Array of Counters or "Tallying" 8 3 0 1 2 2 0 7 2 public static int[] numCount(Scanner input) { int[] counts = ; while (input.hasNextInt()) { int num = input.nextInt(); } return counts; } Lesson 17 - Winter 2024 10
(PCM) Common Ideas in Array Patterns Loop bounds Direction of traversal Indexing into an array Lesson 17 - Winter 2024 11