Computers and Technology

Fill in the missing code: this recursive method returns "even" if the length of a give string is even, and "odd" if the length of the string is odd.

public static string foo(string s)

{

if (s. length() ==0)
return "even";
else if (s. length() = = 1)
return "odd";
else

//your code goes here

}

(40 pts) you coded the following in the file test. java :
system. out. println( foo(5));
//more code here

public static int foo(int n) //line 9

{

if (n = = 0)
return 1;
else

system. out. println(n* foo(n-1) );

} //line 15

at compile time, you get the following error:
text. java: 15: missing return statement

} //line 15

^

1 error

explain what the problem is and how to fix it.

answer
Answers: 3
Get

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:30, dpinzoner5952
Which of the following commands is more recommended while creating a bot?
Answers: 1
image
Computers and Technology, 23.06.2019 01:30, marmar72
Negative methods of behavior correction include all but this: sarcasm verbal abuse setting an example for proper behavior humiliation
Answers: 1
image
Computers and Technology, 23.06.2019 16:30, azainababbas
20 points archie wants to use a reflector as he photographs a newlywed couple. what would he consider in his choice? a. shadow and sunny b. homemade and professional c. lamps and boards d. incident and reflected e. neutral density and enhancement
Answers: 3
image
Computers and Technology, 23.06.2019 18:00, yedida
File account. java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since itÒ€ℒs an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
Do you know the correct answer?
Fill in the missing code: this recursive method returns "even" if the length of a give string is ev...

Questions in other subjects:

Konu
Mathematics, 31.01.2020 10:47
Konu
Mathematics, 31.01.2020 10:47
Konu
Mathematics, 31.01.2020 10:47
Konu
Computers and Technology, 31.01.2020 10:47
Total solved problems on the site: 7600178