subject

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.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:00
How is the number 110 written when expanded out to place values in the base 2 (binary) number system? options: 2 x 4 + 3 x 2 + 4 x 1 1 x 2 + 1 x 2 + 0 x 2 1 x 100 + 1 x 10 + 0 x 1 1 x 4 + 1 x 2 + 0 x 1
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
For her science class, elaine is creating a presentation on weather in the united states. she wants to make the presentation beautiful and interesting by drawing simple cloud or wave shapes. which is the best way for elaine to draw these shapes?
Answers: 1
question
Computers and Technology, 23.06.2019 03:00
What are the different parts of computer
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
Python. primary u.s. interstate highways are numbered 1-99. odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. thus, the 405 services the 5, and the 290 services the 90. given a highway number, indicate whether it is a primary or auxiliary highway. if auxiliary, indicate what primary highway it serves. also indicate if the (primary) highway runs north/south or east/west.
Answers: 1
You know the right answer?
Public class myclass
{
private map map;
public myclass()
{
map = ne...
Questions
question
Mathematics, 19.01.2021 23:40
question
Biology, 19.01.2021 23:40