Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What will the following code print? Can you change the code to work for a String 2D array instead of an int array? Note that

What will the following code print? Can you change the code to work for a String 2D array instead of an int array? Note that the indices row and col will still be ints.

public class Search

{

public static boolean search(int[][] array, int value)

{

boolean found = false;

for (int row = 0; row < array.length; row++)

{

for (int col = 0; col < array[0].length; col++)

{

if (array[row][col] == value)

found = true;

}

}

return found;

}

public static void main(String[] args)

{

int[][] matrix = { {3,2,3},{4,3,6},{8,9,3},{10,3,3} };

System.out.println(search(matrix,10));

System.out.println(search(matrix,11));

// Comment out the code above, and try these:

// String[][] matrix2 = { {"a","b","c"},{"d","e","f"} };

// System.out.println(search(matrix2, "b"));

}

}

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

What is goodwill and how is it measured?

Answered: 1 week ago

Question

How is a futures contract settled?

Answered: 1 week ago