SlideShare a Scribd company logo
1 of 2
Insert the missing code in the following code fragment. This fragment is intended to recursively
compute xn, where x and n are both non-negative integers:
public int power(int x, int n)
{
if (n == 0)
{
____________________
} else
{
return x * power(x, n - 1);
} }
a) return 1;
b) return x;
c) return power(x, n - 1);
d) return x * power(x, n - 1);
Solution
And: a) return 1;
public int power(int x, int n){
// base case, zero power of any number is 1
if(n==0){
return 1;
}
else{
return x*pow(x, n-1);
}
}

More Related Content

More from rtodd972

More from rtodd972 (18)

In what way (or ways) is the current Knowledge Revolution a child of t.docx
In what way (or ways) is the current Knowledge Revolution a child of t.docxIn what way (or ways) is the current Knowledge Revolution a child of t.docx
In what way (or ways) is the current Knowledge Revolution a child of t.docx
 
In the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docxIn the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docx
 
In the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docxIn the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docx
 
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docxiron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
 
It has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docxIt has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docx
 
ISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docxISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docx
 
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docxIs TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
 
Is there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docxIs there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docx
 
In the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docxIn the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docx
 
Is it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docxIs it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docx
 
Is a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docxIs a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docx
 
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docxIs a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
 
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docxIron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
 
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docxInvestors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
 
ionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docxionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docx
 
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
Invoke Netbeans and create a project Exercise 7-  Enter the following.docxInvoke Netbeans and create a project Exercise 7-  Enter the following.docx
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
 
Investors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docxInvestors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docx
 
In the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docxIn the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Insert the missing code in the following code fragment- This fragment.docx

  • 1. Insert the missing code in the following code fragment. This fragment is intended to recursively compute xn, where x and n are both non-negative integers: public int power(int x, int n) { if (n == 0) { ____________________ } else { return x * power(x, n - 1); } } a) return 1; b) return x; c) return power(x, n - 1); d) return x * power(x, n - 1); Solution And: a) return 1; public int power(int x, int n){
  • 2. // base case, zero power of any number is 1 if(n==0){ return 1; } else{ return x*pow(x, n-1); } }