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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, melissalopez12
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
image
Computers and Technology, 22.06.2019 22:40, ihatemylife0
Least square fit to polynomial write a function leastsquarefit3pol that solves a linear system of equations to find a least squares fit of a third order polynomial to an experimental data set given as two row arrays. the function leastsquarefit3pol must explicitly solve a set of linear equations and cannot use polyfit. there should be no restriction on the size of the problem that can be solved.
Answers: 1
image
Computers and Technology, 23.06.2019 02:00, magicalunicorns47
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
Answers: 2
image
Computers and Technology, 23.06.2019 02:30, jaueuxsn
Which component acts as a platform on which application software runs
Answers: 2
You know the right answer?
Public class myclass
{
private map map;
public myclass()
{
map = ne...

Questions in other subjects:

Konu
Mathematics, 20.02.2020 08:28
Konu
Mathematics, 20.02.2020 08:28