SlideShare a Scribd company logo
1 of 2
Download to read offline
* PROBLEM 4: Run runTerribleLoop for one hour. You can stop the program using the red
"stop" square in eclipse. Fill in the OUTPUT line below with the
numbers you saw LAST --- edit the line, replacing the two ... with what you saw:
*
* OUTPUT: terribleFibonacci(...)=... // TODO
*
* Comment: the code uses "long" variables, which are like "int", but
* bigger. It's because fibonacci numbers get really big really fast.
*/
public static void runTerribleLoop () {
for (int N = 0; N < 100; N++)
StdOut.format ("terribleFibonacci(%2d)=%d ", N, terribleFibonacci (N));
}
public static void runTerribleSomeValues () {
StdOut.format ("terribleFibonacci(%2d)=%d ", 13, terribleFibonacci (13));
StdOut.format ("terribleFibonacci(%2d)=%d ", 7, terribleFibonacci (7));
StdOut.format ("terribleFibonacci(%2d)=%d ", 21, terribleFibonacci (21));
}
public static long terribleFibonacci (int n) {
if (n <= 1) return n;
return terribleFibonacci (n - 1) + terribleFibonacci (n - 2);
}
Solution
I think you are looking for Fibonacci program, as you have mentioned it as
TODO in the question.
Please find the Fibonacci program as below.
public static long terribleFibonacci(long n){
// declare 2 numbers to hold the results.
// n1 and n2 hold initial values i.e. 0 and 1.
long n1=0;
long n2=1;
long n3;
for(int i=2;i

More Related Content

Similar to PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf

Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
rafbolet0
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
jyothimuppasani1
 

Similar to PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf (20)

Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
 
Gsp 215 Believe Possibilities / snaptutorial.com
Gsp 215  Believe Possibilities / snaptutorial.comGsp 215  Believe Possibilities / snaptutorial.com
Gsp 215 Believe Possibilities / snaptutorial.com
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
Gsp 215 Enthusiastic Study / snaptutorial.com
Gsp 215 Enthusiastic Study / snaptutorial.comGsp 215 Enthusiastic Study / snaptutorial.com
Gsp 215 Enthusiastic Study / snaptutorial.com
 
GSP 215 Technology levels--snaptutorial.com
GSP 215 Technology levels--snaptutorial.comGSP 215 Technology levels--snaptutorial.com
GSP 215 Technology levels--snaptutorial.com
 
Gsp 215 Massive Success / snaptutorial.com
Gsp 215  Massive Success / snaptutorial.comGsp 215  Massive Success / snaptutorial.com
Gsp 215 Massive Success / snaptutorial.com
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Gsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.comGsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.com
 
GSP 215 Education Organization - snaptutorial.com
GSP 215  Education Organization - snaptutorial.comGSP 215  Education Organization - snaptutorial.com
GSP 215 Education Organization - snaptutorial.com
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
Stacks
StacksStacks
Stacks
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
Practiceproblems(1)
Practiceproblems(1)Practiceproblems(1)
Practiceproblems(1)
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 

More from irshadkumar3

Use the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdfUse the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdf
irshadkumar3
 
What are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdfWhat are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdf
irshadkumar3
 
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdfUsing Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
irshadkumar3
 
please help! READ th.pdf
please help! READ th.pdfplease help! READ th.pdf
please help! READ th.pdf
irshadkumar3
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
irshadkumar3
 
How do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdfHow do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdf
irshadkumar3
 
How do auditors gain an understanding of the internal controls in an.pdf
How do auditors gain an understanding of the internal controls in an.pdfHow do auditors gain an understanding of the internal controls in an.pdf
How do auditors gain an understanding of the internal controls in an.pdf
irshadkumar3
 

More from irshadkumar3 (20)

Describe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdfDescribe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdf
 
A woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdfA woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdf
 
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdfA 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
 
Use the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdfUse the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdf
 
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdfWhich of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdf
 
What are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdfWhat are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdf
 
what are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdfwhat are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdf
 
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdfUsing Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
 
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdfThe _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
 
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdfThe functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
 
Silica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdfSilica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdf
 
Rank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdfRank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdf
 
Compare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdfCompare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdf
 
please help! READ th.pdf
please help! READ th.pdfplease help! READ th.pdf
please help! READ th.pdf
 
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdfIn 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
 
Identify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdfIdentify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdf
 
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdfIA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
 
How do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdfHow do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdf
 
How do auditors gain an understanding of the internal controls in an.pdf
How do auditors gain an understanding of the internal controls in an.pdfHow do auditors gain an understanding of the internal controls in an.pdf
How do auditors gain an understanding of the internal controls in an.pdf
 

Recently uploaded

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 

PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf

  • 1. * PROBLEM 4: Run runTerribleLoop for one hour. You can stop the program using the red "stop" square in eclipse. Fill in the OUTPUT line below with the numbers you saw LAST --- edit the line, replacing the two ... with what you saw: * * OUTPUT: terribleFibonacci(...)=... // TODO * * Comment: the code uses "long" variables, which are like "int", but * bigger. It's because fibonacci numbers get really big really fast. */ public static void runTerribleLoop () { for (int N = 0; N < 100; N++) StdOut.format ("terribleFibonacci(%2d)=%d ", N, terribleFibonacci (N)); } public static void runTerribleSomeValues () { StdOut.format ("terribleFibonacci(%2d)=%d ", 13, terribleFibonacci (13)); StdOut.format ("terribleFibonacci(%2d)=%d ", 7, terribleFibonacci (7)); StdOut.format ("terribleFibonacci(%2d)=%d ", 21, terribleFibonacci (21)); } public static long terribleFibonacci (int n) { if (n <= 1) return n; return terribleFibonacci (n - 1) + terribleFibonacci (n - 2); } Solution I think you are looking for Fibonacci program, as you have mentioned it as TODO in the question. Please find the Fibonacci program as below. public static long terribleFibonacci(long n){ // declare 2 numbers to hold the results. // n1 and n2 hold initial values i.e. 0 and 1. long n1=0; long n2=1;