1) Observe the code below, and then complete the matching to explain the different parts: please explain why also

import java.util.Scanner; public class TwoDArraySearch { public static void main(String[] args){ Scanner scan = new Scanner(System.in); // Part A String[][] people = new String[2][5]; // Part B for(int column = 0; column

Part A

      [ Choose ]            We ask the user to enter an age, and then save it in the next column. Ages are all saved in row 1.            Call a method and send in only row 0 of our people 2d array, and the name we are looking for. Remember that row 0 are the names.            Declare a 2D array of Strings. It has 5 rows and 2 columns.            We loop through the number of rows in the 2d array.            Declare a 2D array of Strings. It has 2 rows and 5 columns.            After running through the smaller for loop, user println() to go down a line (for nice formatting!)            We loop through the number of columns in the 2d array.            A void method that takes in a 2D array and displays its elements            We ask the user to enter a name, and then save it in the next column. Names are all saved in row 0.            Loop through both the rows and columns using a nested for loop, and display each element.            We are using the exact same searching method as Section 1. Notice how it is taking in a single-dimensional array.            A method that takes in a 2D array and a key to be searched for            Display the element at Row 0 and Column foundIndex (the person’s name). Also display the element at Row 1 and Column foundIndex (which is age).            Call a method to print the 2d array            Ask the user who they would like to search for      

Part B

      [ Choose ] from above options   

Part C

        [ Choose ] from above options   

Part D

         [ Choose ] from above options    

Part E

      [   [ Choose ] from above options   

Part F

         [ Choose ] from above options

Part G

      [ Choose ]                [ Choose ] from above options   

Part H

          [ Choose ] from above options   

Part I

          [ Choose ] from above options   

Part J

         [ Choose ] from above options    

Part K

         [ Choose ] from above options   

Part L

    [ Choose ] from above options   

2) How do you find the number of columns in a 2d array? Let’s say our 2D array is called accounts.

A- accounts.length

B- accounts.length()

C- accounts[0].length

D- accounts[0].length()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *