Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class MyClass { private Map map; public MyClass() { map = new HashMap (); map.put(foo, 1); map.put(bar, 3); } public int getValue(String input, int

public class MyClass { private Map map; public MyClass() { map = new HashMap<>(); map.put("foo", 1); map.put("bar", 3); } public int getValue(String input, int numRetries) throws Exception { try { return map.get(input); } catch (Exception e) { if (numRetries > 3) { throw e; } return getValue(input, numRetries + 1); } } } Question: How many times will 'getValue()' execute with the following inputs, and what will be the result? (1) getValue("foo", 0); (2) getValue("bar", 2); (3) getValue("baz", 0); (4) getValue("fubar", 1);

My answer is as follows, I would just like to see if it is correct:

1) runs getValue 1 time and returns 1 2) runs getValue 1 time and returns 3 3) runs getValue 3 times and throws an exception after the third run 4) runs getValue 2 times and throws an exception after the second run

In total getValue runs 7 times

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

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

4. What other challenges may Starbucks encounter in the future?

Answered: 1 week ago

Question

Determine the distribution function of min0yt X(y).

Answered: 1 week ago

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago