Chapter 7 Ch 1 Introduction to Computers and




![An array object stores multiple values MEMORY int[] num = new int[3]; num 5 An array object stores multiple values MEMORY int[] num = new int[3]; num 5](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-5.jpg)
![Arrays Deconstructed MEMORY num[0] 0 int[] num = new int[3]; Declaration num[1] 0 Allocation Arrays Deconstructed MEMORY num[0] 0 int[] num = new int[3]; Declaration num[1] 0 Allocation](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-6.jpg)
![Array objects can hold any type of object int[] number = new int[100]; // Array objects can hold any type of object int[] number = new int[100]; //](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-7.jpg)
![Array elements are initialized to the type's default value MEMORY num[0] 0 int[] = Array elements are initialized to the type's default value MEMORY num[0] 0 int[] =](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-8.jpg)
![You may initialize an array explicitly int[] numbers = {1, 2, 3, 4, 5}; You may initialize an array explicitly int[] numbers = {1, 2, 3, 4, 5};](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-9.jpg)
![Array elements are indexed int[] numbers = new int[5]; MEMORY numbers [0] 1 numbers[0] Array elements are indexed int[] numbers = new int[5]; MEMORY numbers [0] 1 numbers[0]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-10.jpg)
![The index must evaluate to an integral value int[] numbers = new int[5]; int The index must evaluate to an integral value int[] numbers = new int[5]; int](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-11.jpg)





![Arrays can be instance variables public class Department { private Employee[] employee; . . Arrays can be instance variables public class Department { private Employee[] employee; . .](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-17.jpg)
![Arrays can be local variables public void get. Hourly. Employees() { Employee[] hourly. Employee; Arrays can be local variables public void get. Hourly. Employees() { Employee[] hourly. Employee;](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-18.jpg)
![Arrays can be parameters public static void main(String[] args) {. . . } 19 Arrays can be parameters public static void main(String[] args) {. . . } 19](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-19.jpg)
![Code Deconstructed <Method to read an array> public void read. Integer. Numbers(int[] number) { Code Deconstructed <Method to read an array> public void read. Integer. Numbers(int[] number) {](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-20.jpg)
![Arrays can be return values public Employee[] get. Employees() {. . . } 21 Arrays can be return values public Employee[] get. Employees() {. . . } 21](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-21.jpg)
![Code Deconstructed <Method that returns an array> public int[] get. Integer. Array(int elements, int Code Deconstructed <Method that returns an array> public int[] get. Integer. Array(int elements, int](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-22.jpg)
![Arrays are objects, thus int[] a = {1, 2, 3}; int[] b; b = Arrays are objects, thus int[] a = {1, 2, 3}; int[] b; b =](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-23.jpg)
![Code Deconstructed <Method that copies an array> public void copy. Array(int[] source, int[] target) Code Deconstructed <Method that copies an array> public void copy. Array(int[] source, int[] target)](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-24.jpg)
![Arrays are objects, thus int[] a = {1, 2, 3}; int[] b = {1, Arrays are objects, thus int[] a = {1, 2, 3}; int[] b = {1,](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-25.jpg)
![Code Deconstructed <Method that tests for array equality> public boolean are. Equal(int[] array 1, Code Deconstructed <Method that tests for array equality> public boolean are. Equal(int[] array 1,](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-26.jpg)











![Use linear(sequential) search to locate values MEMORY an array [0] 12 Q: is the Use linear(sequential) search to locate values MEMORY an array [0] 12 Q: is the](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-38.jpg)

![You can easily find the min/max value MEMORY the array [0] -4 Assume min You can easily find the min/max value MEMORY the array [0] -4 Assume min](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-40.jpg)


![Selection Sort <Pass 1> MEMORY [0] -4 [1] 7 [2] 9 [3] -6 [4] Selection Sort <Pass 1> MEMORY [0] -4 [1] 7 [2] 9 [3] -6 [4]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-43.jpg)
![Selection Sort <Pass 2> MEMORY [0] -6 [1] 7 [2] 9 [3] -4 [4] Selection Sort <Pass 2> MEMORY [0] -6 [1] 7 [2] 9 [3] -4 [4]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-44.jpg)
![Selection Sort <Pass 3> MEMORY [0] -6 [1] -4 [2] 9 [3] 7 [4] Selection Sort <Pass 3> MEMORY [0] -6 [1] -4 [2] 9 [3] 7 [4]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-45.jpg)
![Selection Sort <Pass 4> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] Selection Sort <Pass 4> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-46.jpg)
![Selection Sort <Array sorted> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] Selection Sort <Array sorted> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-47.jpg)


![Code Deconstructed <selection. Sort> private static void display. Array(int[] number) { for (int i Code Deconstructed <selection. Sort> private static void display. Array(int[] number) { for (int i](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-50.jpg)
![Code Deconstructed <selection. Sort> private static int index. Of. Next. Smallest(int start. Index, int[] Code Deconstructed <selection. Sort> private static int index. Of. Next. Smallest(int start. Index, int[]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-51.jpg)

![2 D : Matrix Columns Rows [0] [1] [2] [0] 1 2 3 [1] 2 D : Matrix Columns Rows [0] [1] [2] [0] 1 2 3 [1]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-53.jpg)
![Physical memory layout MEMORY [0] [1] Columns [0] [1] [2] Rows 5 x 2 Physical memory layout MEMORY [0] [1] Columns [0] [1] [2] Rows 5 x 2](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-54.jpg)
![2 D arrays have both rows and columns string[][] full. Name = String[STUDENT_COUNT][2]; double[][] 2 D arrays have both rows and columns string[][] full. Name = String[STUDENT_COUNT][2]; double[][]](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-55.jpg)


![Code Deconstructed <Initializing a 2 D array> int[][] mat = new int[2][3]; // The Code Deconstructed <Initializing a 2 D array> int[][] mat = new int[2][3]; // The](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-58.jpg)
![Code Deconstructed <Keyboard input> public void read. Names. From. Keyboard(String[][] name) { // Ask Code Deconstructed <Keyboard input> public void read. Names. From. Keyboard(String[][] name) { // Ask](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-59.jpg)
![Code Deconstructed <Screen output> public void write. Names. To. Screen(String[][] name) { // Display Code Deconstructed <Screen output> public void write. Names. To. Screen(String[][] name) { // Display](https://slidetodoc.com/presentation_image_h2/27be1ba93ffc81ccbf78563158973dea/image-60.jpg)
- Slides: 60
Chapter 7 Ch 1 – Introduction to Computers and Java Arrays 1
Chapter 7 7. 1 Array Basics 7. 2 Arrays in Classes and Methods 7. 3 Programming with Arrays and Classes 7. 4 Sorting and Searching Arrays 7. 5 Multidimensional Arrays 2
7. 1 Array Basics num 1 10 num 2 20 num 3 30 3
A simple variable stores a single value MEMORY int num 1 = 10; num 1 10 int num 2 = 20; num 2 20 int num 3 = 30; num 3 30 4
An array object stores multiple values MEMORY int[] num = new int[3]; num 5
Arrays Deconstructed MEMORY num[0] 0 int[] num = new int[3]; Declaration num[1] 0 Allocation num[2] 0 6
Array objects can hold any type of object int[] number = new int[100]; // stores 100 integers double[] sales. Tax = new double[10]; // stores 10 doubles char[] alphabet = new char[26]; // stores 26 characters The size of the array determines the number of elements in the array. 7
Array elements are initialized to the type's default value MEMORY num[0] 0 int[] = new num[3]; num[1] 0 num[2] 0 8
You may initialize an array explicitly int[] numbers = {1, 2, 3, 4, 5}; MEMORY [0] 1 [1] 2 numbers [2] 3 [3] 4 [4] 5 9
Array elements are indexed int[] numbers = new int[5]; MEMORY numbers [0] 1 numbers[0] = 1; [1] 2 numbers[1] = 2; [2] 0 [3] 0 [4] 0 10
The index must evaluate to an integral value int[] numbers = new int[5]; int index = 3; char c = 'C'; numbers[0] = 1; // an integral constant numbers[index] = 3; //an integer variable numbers[c – 'A'] = 2; // c – 'A' = 'C' – 'A' // = 67 – 65 = 2 11
Code Deconstructed <Declare an array of int> // (1) Declare an array to store the number of children // living in each of the 100 houses in a city subdivision. int[] number. Of. Children. Per. House = new int[100]; // (2) Declare an array to store the number of children // living in each of the 100 houses in a city subdivision. final int NUMBER_OF_HOUSES_IN_SUBDIVISION = 100; int[] number. Of. Children. Per. House = new int[NUMBER_OF_HOUSES_IN_SUBDIVISION ]; 12
Code Deconstructed <Read an array of int> // Read from the keyboard 100 values into the array. for (int house = 0; house < NUMBER_OF_HOUSES_IN_SUBDIVISION; house++) { System. out. println("Enter number of children for house " + (house + 1) + ": "); number. Of. Children. Per. House[house] = keyboard. next. Int(); } // end for Enter number of children for house 1: 3 Enter number of children for house 2: 2. . . Enter number of children for house 100: 1 13
Code Deconstructed <Display an array of int> // Display to the screen the array. for (int house = 0; house < NUMBER_OF_HOUSES_IN_SUBDIVISION; house++) { System. out. println("Number of children for house " + (house + 1) + ": " + number. Of. Children. Per. House[house]); } // end for Number of children for house 1: 3 Number of children for house 2: 2. . . Number of children for house 100: 1 14
Brainteaser time! You want to track the daily high and low temperatures for the month of July. The temperature values will be entered by the user at the keyboard. Once all the temperatures have been entered, the program will compute the daily temperature difference and store that as well. Finally, all three values are to be displayed to the screen. 15
7. 2 Arrays in Classes and Methods 16
Arrays can be instance variables public class Department { private Employee[] employee; . . . } 17
Arrays can be local variables public void get. Hourly. Employees() { Employee[] hourly. Employee; . . . } 18
Arrays can be parameters public static void main(String[] args) {. . . } 19
Code Deconstructed <Method to read an array> public void read. Integer. Numbers(int[] number) { System. out. print("Enter " + number. length + " integers: "); Scanner keyboard = new Scanner(System. in); for (int i = 0; i < number. length; i++) { number[i] = keyboard. next. Int(); }// end for }// end read. Integer. Numbers() 20
Arrays can be return values public Employee[] get. Employees() {. . . } 21
Code Deconstructed <Method that returns an array> public int[] get. Integer. Array(int elements, int init. Value) { int[] array = new int[elements]; for (int i = 0; i < array. length; i++) { array[i] = init. Value; }// end for return array; }// end read. Integer. Numbers() 22
Arrays are objects, thus int[] a = {1, 2, 3}; int[] b; b = a; // makes b and a refer to the same // memory location 23
Code Deconstructed <Method that copies an array> public void copy. Array(int[] source, int[] target) { // Both arrays must be the same size. target = new int[source. length]; for (int i = 0; i < source. length; i++) { target[i] = source[i]; }// end for }// end read. Integer. Numbers() 24
Arrays are objects, thus int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; if (a == b) {. . . } // evaluates to false // since a and b refer to two // different memory locations 25
Code Deconstructed <Method that tests for array equality> public boolean are. Equal(int[] array 1, int[] array 2) { if (array 1. length != array 2. length) { return false; } else { for(int i = 0; i < array 1. length; i++) { if(array 1[i] != array 2[i]) return false; }// end for }// end if return true; }// end read. Integer. Numbers() 26
Brainteaser time! § You want to use a class to store some personal information on the 5 people you just met at a conference. § You want to save their name, and address, along with their cell phone number. § You decide to write a small program that inputs the records and displays them to the screen. 27
7. 3 Programming with Arrays and Classes 28
Application Deconstructed <No. Duplicates. List. Demo. java> package noduplicateslistdemo; public class No. Duplicates. List. Demo { public static void main(String[] args) { No. Duplicates. List nfl. Teams = new No. Duplicates. List(4); String team; nfl. Teams. add. Item("Chicago Bears"); nfl. Teams. add. Item("Miami Dolphins"); nfl. Teams. add. Item("St. Louis Rams"); nfl. Teams. add. Item("Chicago Bears"); nfl. Teams. add. Item("Dallas Cowboys"); nfl. Teams. add. Item("Arizona Cardinals"); 29
Application Deconstructed <No. Duplicates. List. Demo. java> nfl. Teams. move. First(); team = nfl. Teams. get. Next(); while (team != null) { System. out. println("Team: " + team); team = nfl. Teams. get. Next(); }// end while }// end main() }// end No. Duplicates. List. Demo 30
Application Deconstructed <No. Duplicates. List. Demo. java> package noduplicateslistdemo; public class No. Duplicates. List { private static final int DEFAULT_LIST_SIZE = 100; private String[] items; private int number. Of. Items; private int index. Of. Current. Item; // Allocates the array and updates the number. Of. Items. private void set(int list. Size) { items = new String[list. Size]; number. Of. Items = 0; }// end set() 31
Application Deconstructed <No. Duplicates. List. Demo. java> // Returns true if item already exists on the list. private boolean is. On. List(String item) { boolean found = false; int i = 0; while (!found && i < number. Of. Items) { if (items[i]. equals. Ignore. Case(item)) { found = true; } else { i++; }// end if }// end while return found; }// end is. On. List() 32
Application Deconstructed <No. Duplicates. List. Demo. java> // Allocates an array of default size. public No. Duplicates. List() { this(DEFAULT_LIST_SIZE); }// end No. Duplicates. List() public No. Duplicates. List(int initial. List. Size) { set(initial. List. Size); }// end No. Duplicates. List() // Sets the index. Of. Current. Item to 0. public void move. First() { index. Of. Current. Item = 0; }// end move. First() // Returns the first item. public String get. First() { if(number. Of. Items != 0) return items[0]; else return null; }// end get. First() 33
Application Deconstructed <No. Duplicates. List. Demo. java> // Returns the last item. public String get. Last() { if(number. Of. Items != 0) return items[number. Of. Items - 1]; else return null; }// end get. Last() // Returns the next item in the list. If the current item // happens to be the last one, then it returns null. public String get. Next() { String item = null; if (index. Of. Current. Item < number. Of. Items) { item = items[index. Of. Current. Item]; index. Of. Current. Item++; }// end if return item; }// end get. Next() 34
Application Deconstructed <No. Duplicates. List. Demo. java> // Returns true if list is empty, false otherwise. public boolean is. Empty() { return number. Of. Items == 0; }// end is. Empty() // Returns true is list is full, false otherwise. public boolean is. Full() { return number. Of. Items == items. length; }// end is. Full() 35
Application Deconstructed <No. Duplicates. List. Demo. java> // Adds the item to the end of the list, but without // duplicates. Updates the index. Of. Current. Item to point to // this item. public void add. Item(String item) { if (is. Full()) { System. out. println("List is full. "); } else if (!is. On. List(item)) { items[number. Of. Items] = item; index. Of. Current. Item = number. Of. Items; number. Of. Items++; }// end if }// end add. Item() }// end No. Duplicates. List 36
7. 4 Sorting and Searching Arrays 37
Use linear(sequential) search to locate values MEMORY an array [0] 12 Q: is the value? A: No [1] 1 Q: is the value? A: No [2] 44 Q: is the value? A: No Q: is the value? A: Yes [3] 15 [4] 6 Q: is the value 15 in the array? 38
Code Deconstructed <Linear Search> // Returns true if array contains item, false otherwise. private boolean Contains(String[] items, String item) { for(int i = 0; i < items. length; i++) { if (items[i]. equals. Ignore. Case(item)) { return true; } }// end for return false; }// end Contains() 39
You can easily find the min/max value MEMORY the array [0] -4 Assume min = -4 [1] 7 (7 < -4)? No [2] 9 [3] -6 (9 < -4)? No (-6 < -4)? Yes, min = -6 [4] 12 (12 < -6)? No 40
Code Deconstructed <Find index of next smallest> // Returns the index of the next smallest value in the array. private int index. Of. Next. Smallest(int start. At, int[] list) { // Assume smallest value is at start. At. int min. Index = start. At; // Now, let's try and find another value that is less. for (int i = start. At; i < list. length; i++) { min. Index = (list[i] < list[min. Index])? i : min. Index; }// end for return min. Index; }// end index. Of. Next. Smallest() 41
Selection Sort Deconstructed § Go through the array n – 1 times, where n is array size. § In each pass, select next value in order (smallest, largest) § Exchange with top value in unordered portion § Continue with next value until no more values left 42
Selection Sort <Pass 1> MEMORY [0] -4 [1] 7 [2] 9 [3] -6 [4] 12 Pass 1 of 4 Find the next value in order MEMORY [0] -6 [1] 7 [2] 9 [3] -4 [4] 12 Exchange with top value 43
Selection Sort <Pass 2> MEMORY [0] -6 [1] 7 [2] 9 [3] -4 [4] 12 Pass 2 of 4 Find the next value in order MEMORY [0] -6 [1] -4 [2] 9 [3] 7 [4] 12 Exchange with top value 44
Selection Sort <Pass 3> MEMORY [0] -6 [1] -4 [2] 9 [3] 7 [4] 12 Pass 3 of 4 Find the next value in order MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] 12 Exchange with top value 45
Selection Sort <Pass 4> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] 12 Pass 4 of 4 Find the next value in order MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] 12 Exchange with top value 46
Selection Sort <Array sorted> MEMORY [0] -6 [1] -4 [2] 7 [3] 9 [4] 12 After 4 passes the array is in order 47
Code Deconstructed <selection. Sort> // Sorts the array in ascending order. private void selection. Sort(int[] array[]) { int min. Index; for (int top. Index = 0; top. Index < array. length – 1; top. Index++) { // Find the next smallest value. min. Index = index. Of. Next. Smallest(top. Index, array); // Exchange with top value. swap(top. Index, min. Index, array); }// end for }// end Selection. Sort() // Swaps the two values identified by the top and min. Index // paramaters. private void swap(int index 1, int index 2, int[] array) { int tmp = array[index 1]; array[index 1] = array[index 2]; array[index 2] = tmp; }// end swap() 48
Application Deconstructed <selection. Sort. Demo. java> package selectionsortdemo; public class Selection. Sort. Demo { public static void main(String[] args) { int[] number = {-4, 0, 5, 12, 9, 5, -20, 30}; System. out. println("Original array: "); display. Array(number); selection. Sort(number); System. out. println(); System. out. println("Sorted array: "); display. Array(number); System. out. println(); }// end main() 49
Code Deconstructed <selection. Sort> private static void display. Array(int[] number) { for (int i = 0; i < number. length; i++) { System. out. print(number[i] + " "); }// end for }// end display. Array() private static void selection. Sort(int[] number) { for (int top. Index = 0; top. Index < number. length - 1; top. Index++) { swap(top. Index, index. Of. Next. Smallest(top. Index, number); }// end for }// end selection. Sort() 50
Code Deconstructed <selection. Sort> private static int index. Of. Next. Smallest(int start. Index, int[] array) { int min. Index = start. Index; for (int i = start. Index; i < array. length; i++) { min. Index = (array[i] < array[min. Index])? i : min. Index; }// end for return min. Index; }// end index. Of. Next. Smallest() private static void swap(int index 1, int index 2, int[] array) { int tmp = array[index 1]; array[index 1] = array[index 2]; array[index 2] = tmp; }// end swap() }// end selection. Sort. Demo 51
7. 5 Multidimensional arrays 52
2 D : Matrix Columns Rows [0] [1] [2] [0] 1 2 3 [1] 4 5 6 [2] 7 8 9 [3] 10 11 12 [4] 13 14 15 MEMORY 5 x 3 array
Physical memory layout MEMORY [0] [1] Columns [0] [1] [2] Rows 5 x 2 array [0] [3] [1] [0] [1] [4]
2 D arrays have both rows and columns string[][] full. Name = String[STUDENT_COUNT][2]; double[][] city. Sales. Tax = new double[STATE_COUNT][CITY_COUNT]; int[][] student. Scores = new int[STUDENT_COUNT][ASSESSMENT_COUNT];
Brainteaser time! A two-dimensional array for recording the daily lo and hi temperatures for 2002, for the county of Madison, Illinois. int daily. Lo. Hi. Temp. For. Madison[365][2]; int daily. Lo. Hi. Temp. For. Madison[2][365]; A two-dimensional array for recording the annual average rainfall for all 50 states for the last 10 years. int annual. Average. Rainfall. For. USStates[50][10]; int annual. Average. Rainfall. For. USStates[10][50];
Initializing 2 D arrays // Use initializer list to assign values in row // first order. int[][] mat = { {1, 2, 3} {4, 5, 6} }; [0] [1] [2] [0] 1 2 3 [1] 4 5 6
Code Deconstructed <Initializing a 2 D array> int[][] mat = new int[2][3]; // The outer for represents the rows. // The inner the columns. for (int r = 0; r < 2; r++) { for (int c = 0; c < 3; c++) { mat[r][c] = r * 3 + c + 1; }// end for [0] [1] [2] [0] 1 2 3 [1] 4 5 6
Code Deconstructed <Keyboard input> public void read. Names. From. Keyboard(String[][] name) { // Ask the user for name. length names. for (int row = 0; row < name. length; row++) { System. out. println("Enter name [First Last]: "); for (int col = 0; col < name[row]. length; col++) { name[row][col] = keyboard. next(); }// end for }// end read. Names. From. Keyboard()
Code Deconstructed <Screen output> public void write. Names. To. Screen(String[][] name) { // Display each name to the screen, one per line. for (int row = 0; row < name. length; row++) { for (int col = 0; col < name[row]. length; col++) { System. out. println(name[row][col]); }// end for }// end write. Names. To. Screen()