Write a recursive method named power that accepts two integers representing a base and an exponent and returns the base raised to that exponent. For example, the call of power(3, 4) should return 34 or 81 . If the exponent passed is negative, throw an IllegalArgumentException. Do not use loops or auxiliary data structures; solve the problem recursively. Also do not use the provided Java pow method in your solution.

Answers

Answer 1

Answer:

The method in java is as follows:

   public static int power(int num, int exp){

       if(exp == 0){            return 1;        }

       if(exp < 0){

           throw new IllegalArgumentException("Positive exponents only");        }

       else{            return (num*power(num, exp-1));        }

   }

Where

[tex]num\to[/tex] base

[tex]exp \to[/tex] exponent

Explanation:

This defines the method

   public static int power(int num, int exp){

This represents the base case, where the exponent is 0

       if(exp == 0){

If yes, the function returns 1

           return 1;        }

If exponent is negative, this throws illegal argument exception

       if(exp < 0){

           throw new IllegalArgumentException("Positive exponents only");        }

If exponents is positive, this calls the function recursively

       else{            return (num*power(num, exp-1));        }

   }


Related Questions

pleaseeeeeeee tellllllllllllllllllllll​

Answers

Answer:

true is the correct answer

Which of the following is primarily operated by a touchscreen?
Mobile device
Notebook
Desktop
Network

Answers

Answer: The correct answer is Mobile device

Explanation:

A Mobile device is any portable equipment that can be easily connected to an internet. Example of mobile devices include; smart phones, palmtop, smart watch and other computer gadgets. The use of touchscreen for input or output on mobile devices can not be overemphasized. Mobile devices are handy and can be used for making work easy. As such, in order to effectively use mobile devices, touchscreen can be primarily used.

Which tag appears in the element of an HTML file? A. B. C. D. E.

Answers

element the answer is Explanation:

Answer:

<title>

Explanation:

trust me

"To speed up magnetic hard drive performance , ___________ is often used. "

Answers

Answer:

disk caching

Explanation:

Hi,

Magnetic hard drives use disk caching to speed up performance. This method is quite ingenious because what it does is that in a section of memory in your pc, it keeps a copy of information that was previously accessed in the hard disk. So, next time if the same data is requested, the system can refer to cache to get quick access rather than going to the hard disk (which is slower).

write two eaxmple of operating system​

Answers

Answer:

Some examples include versions of Microsoft Windows (like Windows 10, Windows 8, Windows 7, Windows Vista, and Windows XP), Apple's macOS (formerly OS X)

Explanation:

Answer:

windows 10 macOs window xp window 8

Which Product is an example of Interface convergence?
- a key chain with a bottle opener
- a pencil with a flashlight
- a passenger car that uses the same engine as a racing car
- a tablet device that can be connected to a standard keyboard

Answers

Answer:

a tablet device that can be connected to a standard keyboard

Explanation:

// Exercise 4.16: Mystery.java
2 public class Mystery
3 {
4 public static void main(String[] args)
5 {
6 int x = 1;
7 int total = 0;
8
9 while (x <= 10)
10 {
11 int y = x * x;
12 System.out.println(y);
13 total += y;
14 ++x;
15 }
16
17 System.out.printf("Total is %d%n", total);
18 }
19 } // end class Mystery

Answers

Answer:

385

Explanation:

There was no question so I simply run the program for you and included the output.

The program seems to calculate: [tex]\sum\limits_{x=1}^{10} x^2[/tex]

Komunikasi, dengan program ini kita juga bisa berkomunikasi dengan pengguna lain.Program ini sudah dirancang untuk bisa saling bertukar informasi dalam bentuk jaringan dimana orang lain bisa membuka lembar kerja kita dari terminal (komputer) yang berlainan,bahkan ia juga bisa melakukan perubahan pada lembar kerja yang sama pada saat yang bersamaan pula. Kata pengguna lain dapat disebut dengan kata:_____________

Answers

Answer:

what language is this?

Explanation:

What is a document?

a information about a computer file, distinct from the information it contains
a set of information gathered together
a two- to four-letter string set to the right of the dot in a filename; this designates the type of information in the file
a computer file representing a specific text item

Answers

Answer:

A document is a written, drawn, presented, or memorialized representation of thought, often the manifestation of non-fictional, as well as fictional, content. The word originates from the Latin Documentum, which denotes a "teaching" or "lesson": the verb doceō denotes "to teach" In general, a document (noun) is a record or the capturing of some event or thing so that the information will not be lost.  A document is a form of information. A document can be put into an electronic form and stored in a computer as one or more files. Often a single document becomes a single file.

Select the correct answer.
What is the purpose of using graphics and animation in the title sequence of a video production?
A. they are historical remnants from the era of silent films
B. they provide a synopsis of the program
Oc. they are a substitute for dialogues or a voiceover
D. they break the monotony of watching live action
E. they provide a clue about what to expect in a program

Answers

Answer:

They provide a clue about what to expect in a program

What allows you to navigate up down left and right in a spreadsheet?

Answers

Answer:

scrollbar?

Explanation:

____________

Abstract: Design, implement, explain, test, and debug a simple, but complete command- line interpreter named cli.
Detail: Design, implement, document, test and run a simple shell, known here as a command-line interpreter (cli). This tool is invoked via the cli command plus possible arguments. Commands are OS commands to be executed. Multiple commands are separated from one another by commas, and each may in turn require further arguments. Cli 'knows' a list of commands a-priori; they are predefined. When invoked, cli checks, whether the first argument is an included command. If so, cli confirms this via a brief message. If not, a contrary message is emitted, stating this is not one the predefined commands. After the message, cli executes all commands in the order listed. After executing the last command, cli prints the current working directory, i.e. it acts as if the pwd command had been issued. Sample runs are shown further below.
Multiple commands of cli must be separated from one another by commas. Possible parameters of any one command are separated from the command itself (and from possible further parameters) by white space. White space consists of blanks, tabs, or a combination, but at least 1 blank space. Here some sample runs with single and multiple commands; outputs are not shown here: .
/cli pwd looks like Unix command pwd; is your sw .
/cli rm -f temp, mv temp ../temp1 ditto: input to your running homework 5
./cli ls -la another "single unix command"
./cli rm a.out, gcc sys.c, cp a.out cli
Cli starts out identifying itself, also naming you the author, and the release date. Then cli prints the list of all predefine commands. Finally, cli executes all commands input after the cli invocation. For your own debug effort, test your solution with numerous correct and also wrong inputs, including commas omitted, multiple commas, leading commas, illegals commands, other symbols instead of commas etc. No need to show or hand-in your test and debug work.
The output of the cli command "cli pwd" or "./cli pwd" should be as shown below, assuming your current working directory is ./classes Sac State/csc139. Here is the output of a sample run with a single command line argument:
herbertmayer$ ./cli pwd
hgm cli 4/12/2020
Legal commands: cd exec exit gcc Is man more mv rm pwd sh touch which $path
2 strings passed to argv[]
next string is 'pwd'
new string is 'pwd
1st cind 'pwd' is one of predefined
/Users/herbertmayer/herb/academia/classes Sac State/csc139
Here the output of another sample run, also with a single cli command:
herbertmayer$ ./cli ls
hgm cli 4/12/2020
Legal commands: cd exec exit gcc ls man more mv rm pwd sh touch which Spath
2 strings passed to argv[]
next string is 'ls'
new string is 'ls!
1st cmd 'is' is one of predefined. admin cli.c sac state yyy
backup 1 24 2020 docs sac state hw
backup 3 9 2020 grades sac state xxx
cli 1 notes
/Users/herbertmayer/herb/academia/classes Sac State/csc139
Interpretation of commands that cli handles can proceed through system(), executed from inside your C/C++ program cli.
List of all commands supported by your cli:
char * cmds [ ] = {
"cd",
"exec",
"exit",
"gcc",
"ls",
"man",
"more",
"mv",
"Im
"pwd"
"sh",
"touch",
"which",
"Spath"
What you turn in:
1. The source program of your homework solution; well commented, preferably one single source file.
2. Four progressively more complex executions of your correctly working cli program, showing all user inputs and corresponding output responses.

Answers

Answer:

that is very long question ask a profesional

Explanation:

Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address. Write a separate function (not part of the Employee class) named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the whole Employee object. The function should return the resulting dictionary. For example, it could be used l

Answers

Solution :

class Employee:

   #Define the

   #constructor.

   def __[tex]$\text{init}$[/tex]__([tex]$\text{self, nam}e$[/tex],  ID_number, [tex]$\text{salary}$[/tex], email):

       #Set the values of

       #the data members of the class.

       [tex]$\text{self.nam}e$[/tex] = name

       [tex]$\text{self.ID}$[/tex]_number = ID_number

       [tex]$\text{self.salary}$[/tex] = salary

       self.email_address = email

#Define the function

#make_employee_dict().

def make_employee_dict(list_names, list_ID, list_salary, list_email):

   #Define the dictionary

   #to store the results.

   employee_dict = {}

   #Store the length

   #of the list.

   list_len = len(list_ID)

   #Run the loop to

   #traverse the list.

   for i in range(list_len):

       #Access the lists to

       #get the required details.

       name = list_names[i]

       id_num = list_ID[i]

       salary = list_salary[i]

       email = list_email[i]

       #Define the employee

       #object and store

       #it in the dictionary.

       employee_dict[id_num] = Employee(name, id_num, salary, email)

   #Return the

   #resultant dictionary.

   return employee_dict

write a python program that should determine from the range you choose to enter :

The count of even and odd numbers

values divisible by 3

values divisible by 5​

Answers

Answer:

I'm not fully sure if this will work, however, I'm 92% sure it is correct.

Explanation:

startingrange = int(input("Enter a number for the starting of the range: "))

endingrange = int(input("Enter a number for the ending of the range: "))

divisiblebythree = 0

divisiblebyfive = 0

even = 0

odd = 0

for i in range(startingrange, endingrange):

   if (i % 2) == 0:

       even += 1

   elif (i % 2) != 0:

       odd += 1

   if (i % 3) == 0:

       divisiblebythree+=1

   if (i%5) == 0:

       divisiblebyfive+=1

print("Numbers divisible by 5:",divisiblebyfive)

print("Numbers divisible by 3:",divisiblebythree)

print("Odd numbers:",odd)

print("Even numbers:",even)

How do you get off of the comments after you look at them wit out going all the way off the app?

Answers

There should be a little arrow to click and if it is not working or you don’t have one pull the screen down to see if that works :)

How does CSS relate to HTML

Answers

Answer:

CSS stands for Cascading Style Sheets with an emphasis placed on “Style.” While HTML is used to structure a web document (defining things like headlines and paragraphs, and allowing you to embed images, video, and other media), CSS comes through and specifies your document's style—page layouts, colors, and fonts are

Explanation:

Expectation on Information Technology Fundamental​

Answers

You can expect to develop an understanding of information systems, programming languages, information management and artificial intelligence, leaving your studies with the ability to apply your knowledge to solve problems.

hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

Answers

Answer:

hhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

Explanation:

explain the errors in each error in spreadsheet and how to correct each​

Answers

Answer:

###### error. Problem: The column is not wide enough to display all the characters in a cell. ...

# Div/0! error. ...

#Name? error. ...

#Value! error. ...

#REF! error. ...

#NUM! error. ...

#NULL error.

Explanation:

Populations are effected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data:
• The starting size of a population
• The annual birth rate
• The annual death rate
• The number of years to display
Write a function that calculates the size of the population for a year. The formula is
N = P + BP − DP
where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate.
Input Validation: Do not accept numbers less than 2 for the starting size. Do not accept negative numbers for birth rate or death rate. Do not accept numbers less than 1 for the number of years.
#include
using namespace std;
double calcOfPopulation(double, double, double);
double inputValidate(double, int);
int main()
{
double P, // population size
B, // birth rate %
D, // death rate %
num_years;
cout << "Starting size of population: ";
P = inputValidate(P, 2);
cout << "Annual birth rate: %";
B = inputValidate(B, 0);
cout << "Annual death rate: %";
D = inputValidate(D, 0);
cout << "Number of years to display: ";
num_years = inputValidate(num_years, 1);
cout << "Population size for "
<< num_years << " years "
<< " = "
<< (calcOfPopulation(P, B, D) * num_years)
<< endl;
return 0;
} // END int main()
double inputValidate(double number, int limit)
{
while(!(cin >> number) || number < limit)
{
cout << "Error. Number must not be "
<< " 0 or greater:";
cin.clear();
cin.ignore(numeric_limits::max(), '\n');
}
return number;
}
double calcOfPopulation(double P, double B, double D)
{
B *= .01; // 3.33% = .0333
D *= .01; // 4.44% = .0444
return P + (B * P) - (D * P);

Answers

Answer:

See attachment for program source file

Explanation:

The source code in the question is not incorrect; just that, it was poorly formatted.

So, what I did it that:

I edited the source code to be in the right formats.numeric_limits needs the <limits> header file to work properly. The <limits> header file was not included in the original source file; so, I added #include<limits> at the beginning of the source fileI corrected the wrongly declared function prototypes.

See attachment for the modified program source file

Please answer it’s timed

Answers

Product safety cuz it talking about safety

Answer:

product safety

Explanation:

brainly:)^

2.
When parking on hills or an unlevel surface, make sure your
is engaged when you leave the vehicle.
A. turn signal
B. accelerator
C. brake pedal
D. parking brake

Answers

Answer:

D. parking brake

Explanation:

When parameters are passed between the calling code and the called function, formal and actual parameters are matched by: a.

Answers

Answer:

their relative positions in the parameter and argument lists.

Explanation:

In Computer programming, a variable can be defined as a placeholder or container for holding a piece of information that can be modified or edited.

Basically, variable stores information which is passed from the location of the method call directly to the method that is called by the program.

For example, they can serve as a model for a function; when used as an input, such as for passing a value to a function and when used as an output, such as for retrieving a value from the same function. Therefore, when you create variables in a function, you can can set the values for their parameters.

A parameter can be defined as a value that must be passed into a function, subroutine or procedure when it is called.

Generally, when parameters are passed between a calling code and the called function, formal and actual parameters are usually matched by their relative positions in the parameter and argument lists.

A formal parameter is simply an identifier declared in a method so as to represent the value that is being passed by a caller into the method.

An actual parameter refers to the actual value that is being passed by a caller into the method i.e the variables or values that are passed while a function is being called.

How wireless communication might affect the development and implementations of internet of things?​

Answers

If people send a link don’t try them report them!

To iterate through (access all the entries of) a two-dimensional arrays you
need for loops. (Enter the number of for loops needed).

Answers

Answer: You would need two loops to iterate through both dimensions

Explanation:

matrix = [[1,2,3,4,5],

              [6,7,8,9,10],

              [11,12,13,14,15]]

for rows in matrix:

    for numbers in rows:

         print(numbers)

The first loop cycles through all the immediate subjects in it, which are the three lists. The second loop calls the for loop variable and iterates through each individual subject because they are lists. So the first loop iterates through the 1st dimension (the lists) and the seconds loop iterates through the 2nd dimension (the numbers in the lists).

To iterate through (access all the entries of) a two-dimensional arrays you need two for loops.

What is an array?

A collection of identically typed items, such as characters, integers, and floating-point numbers, are kept together in an array, a form of data structure.

A key or index that can be used to retrieve or change the value kept in that location identifies each element in the array.

Depending on how many indices or keys are used to identify the elements, arrays can be one-dimensional, two-dimensional, or multi-dimensional.

Two nested for loops are often required to iterate over a two-dimensional array: one to loop through the rows, and the other to loop through the columns.

As a result, two for loops would be required to access every entry in a two-dimensional array.

Thus, the answer is two for loops are required.

For more details regarding an array, visit:

https://brainly.com/question/19570024

#SPJ6

Write a function called PayLevel that returns a level given an Ssn as input. The level are: "Above Average" if the employee makes more than the average for their department "Average" if the employee makes the average for their department "Below Average" if the employee makes less than the average for their department

Answers

Answer:

Explanation:

Since no further information was provided I created the PayLevel function as requested. It takes the Ssn as input and checks it with a premade dictionary of Ssn numbers with their according salaries. Then it checks that salary against the average of all the salaries and prints out whether it is Above, Below, or Average. The output can be seen in the attached picture below.

employeeDict = {162564298: 40000, 131485785: 120000, 161524444: 65000, 333221845: 48000}

average = 68250

def PayLevel(Ssn):

   pay = employeeDict[Ssn]

   print("Employee " + str(Ssn) + " is:", end=" "),

   if pay > average:

       print("Above Average")

   elif pay < average:

       print("Below Average")

   else:

       print("Average")

PayLevel(161524444)

PayLevel(131485785)

What is the first step you should take when you want to open a savings account? A. Present your photo ID to the bank representative. B. Go to the bank and fill out an application. C. Make your initial deposit. D. Review the different savings account options that your blunk offers.​

Answers

Answer: B

Explanation:

The first step you should take when you want to open a savings account is the photo id

Write a recursive method named digitSum that accepts an integer as a parameter and returns the sum of its digits. For example, calling digitSum(1729) should return 1 7 2 9, which is 19. If the number is negative, return the negation of the value. For example, calling digitSum(-1729) should return -19.

Answers

Answer:

The function in Python is as follows:

def digitSum( n ):

if n == 0:

 return 0

if n>0:

    return (n % 10 + digitSum(int(n / 10)))

else:

    return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))

Explanation:

This defines the method

def digitSum( n ):

This returns 0 if the number is 0

if n == 0:

 return 0

If the number is greater than 0, this recursively sum up the digits

if n>0:

    return (n % 10 + digitSum(int(n / 10)))

If the number is lesser than 0, this recursively sum up the absolute value of the digits (i.e. the positive equivalent). The result is then negated

else:

    return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))

Es el conjunto de manifestaciones materiales, intelectuales y espirituales que distinguen a un pueblo a)Civilización b)Cultura c)Tradiciones d)Costumbres

Answers

Answer:

a)Civilización

Explanation:

how do you fix The lag on your zsnes emulator I’m playing it on My laptop

Answers

Answer:

Use a laptop that is not a potato.

Explanation:

ZSNES has super low system requirements, so if it's running poorly you are probably running it on a potato. You might also try a different emulator such as BSNES, if you think that the problem is not the underpowered computer.

Other Questions
An isosceles right triangle has legs of equal length. If thehypotenuse is 10 centimeters long, find the length of each leg. PLEASE HELP FAST WILL MARK BRAINLIEST PLEASEEE Spanish Homework Answer the following questions in a complete sentences:1. Qu acabas de hacer? 2. Con quin acabas de hablar?3. Adnde acabas de ir? Answer please this is my final grade for the year David ha fabricado una caja de cartn sin tapa para guardar sus cromos la caja tiene una base cuyos lados miden 30 cm y cuya altura mide 10 cm calcula la cantidad de cartn que ha necesitado David Select the correct answer.argument regarding the future of the United States?What is George Washington's mainOA. The United States shouldremain as politically neutral as possible.O B. The United States should form alliances with powerful nations.O C. The United States should isolate itself from all foreign nations.O D. The United States should align its interests with those of Europe.O E. The United States should lead in foreign diplomacy and peacekeeping. What determines the foreign exchange rate?A. The governmentB. Small businessesC. Market forcesD. Consumers Find the exact value of sin A in simplest radical form. please help 20 points and crown (a) "Fostering a strong credit reputation is an important policy a company shouldhave in the management of its trade payables". Discuss this statement. n southern and eastern coastal states, governors often issue evacuation orders when the threat of a hurricane is near. What is one consequence when people choose to ignore official evacuation orders? A. Emergency responders are placed in dangerous situations while attempting rescues. B. Damage to property from hurricane winds and flood waters increases. C. Emergency responders are forced to rely on outdated rescue equipment. D. People have to pay government workers to be rescued in extreme emergencies. Hi, i need to calculate roots x1 and x2 using the vieta theorem, can anyone help me? I have found the answer for x1 and x2, its 1,5 and 2, all i need is a solution on how to get this answer, the equation is in the picture, will give you brainliest if you type down the correct solution for me, thanks. I have left a similar equation that i did. The only thing why i cant do the equation, because in front of x2 theres an number, so i dont understand. What was Mahatma Gandhis first main conflict? Read this excerpt from a story.Miya took a deep breath, squared her shoulders, and entered the kitchen. "Hey, Mom. What's up?""Not much. I'm just paying some bills.""Well, sorry to interrupt, but I wanted to ask you if I could meet some friends at the park. Jamie just texted me, and a bunch of kids are meeting at the soccer field.""What's their plan?""There is no plan. They are just meeting and hanging out.""I'm not sure I like the sound of that. Id prefer a more organized activity.""Organized? Well, we are organized. We are meeting at the park at 4:00.""I'm not sure you'll be joining them."What type of conflict does Miya experience?person vs. selfperson vs. personperson vs. societyperson vs. nature 1.Select two organisms with very different traits (e.g., moss and chimpanzee).Organism 1:Organism 2:Number of genes incommon What is the difference between paper currency and coins? What value from the set 4,5,6,7,8 makes the equation 4x + 3 = 23 true Which phrase describes the expression 505n ? Answer this question to get marked as barinliest!!!!!! Help pretty please .w.