Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please compete all questions. programming language is java. public class WODI public static void main(String[] args) into Il table = new int[3][2]: System.out.println(table.length); System.out.println(table[0].length): The

please compete all questions. programming language is java. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
public class WODI public static void main(String[] args) into Il table = new int[3][2]: System.out.println(table.length); System.out.println(table[0].length): The 2D array can be visualized as a grid or table: Critical Thinking Questions 1. Examine the first line of the main method in TwoD.java. a. What code initializes or sets the number of rows in this 2D array? b. What code initializes or sets the number of columns in this 2D array? c. Explain the difference in Java syntax for declaring a 2D array (as opposed to one-dimensional arrays in Model 1). 2. Examine the rest of the main method. a. What code will print the number of rows in this 2D array? b. What code will print the number of columns in this 2D array? 3. What prints when you add the code: System.out.println(table[0]); 4. The following code would allow you to print the first element in the above 2D array: System.out.println(table[0][0]); Using this two square brackets notation, fill in the indices for each of the six elements in the 2D array: tableto 01 5. Consider how you would write code to print the first row of the two-dimensional array (just the first two elements). a. First give the two lines of similar code that would print the first two elements (both elements on the same line), b. Now consider if the first row had 200 elements instead of 2. Give two lines of code that will print the first row of an array which has 200 elements in its first row. c. Examine your answer to CTQ 2. Give two lines of code that will print the first row of an array, regardless of how many elements it has in each row. 6. Now consider how you would write code to print the second and third rows of the above two-dimensional array, so each row appears on a separate line. a. Where would you need to print a newline? b. Provide the pseudocode for printing the second and third lines (similar to your answer to Question Sc). c. What change must you make to the boolean condition to print the second and third lines? d. Consider how you could use another loop to automate the changes to the boolean condition. Give that pseudocode for that code here (don't worry about the exact variables you'll need) 7. Consider an array with an unknown number of columns. a. How could you use your answer to Question 6 to help you modify the changing boolean condition (your answer to the previous question)? b. Modify the main method so it prints the entire two- dimensional array, regardless of the number of rows and columns it has, and give that code here. 8. Consider the Java code you provided for the previous question. How would you modify the code so as to print only the first half of the grid (the top half of the grid)? You can assume there is an even number of rows. It's possible to create a ragged array, or a 2D array with a different number of elements in each row: public class RaggedArray! public static void main(string[] args) charta ragged - new chart3111: Tagged[0) - new char1511 Tagged[1] - new chart91: ragged 21 - new char (12) int letter - 65: ragged[010] - char) letter: letter 9. Examine the above main method in RaggedArray.java. a. How many rows are in this two-dimensional array? b. How many columns are in the first row of the two- dimensional array? c. How many columns are in the second row of the two- dimensional array? d. How many columns are in the third row of the two- dimensional array? e. Explain how the first element of the array being set to the letter A. 10. Examine your code for printing an entire two-dimensional array (question 7). Would your code work for a ragged array? Why or why not? 11. Explain why a 2D array could also be called "an array of arrays". Team Programming: Copy and paste your code from CTQ 7 into the main method in RaggedArray.java. Modify the code so it sets the first element to 'A', the second element to 'B', and so on, until the last element is set to Z. Then add code to print the elements of the entire array (one row per line) Everyone should turn in their own individual answers: A. What type of error occurs if you use an invalid index number to access an array? B. Give the code for traversing a 2D array (for example, the loops needed to print or initialize every element in a 2D array). You only need to give the loops, not the body of the loops

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

OUTCOME 1 Explain the reasons for equity-related legislation.

Answered: 1 week ago