
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
java
1.1.19 Run the following
public class Fibonacci
{
public static long F(int N)
{
if (N == 0) return 0;
if (N == 1) return 1;
return F(N-1) + F(N-2);
}
public static void main(String[] args)
{
for (int N = 0; N < 100; N++)
StdOut.println(N + " " + F(N));
}
}
Expert Solution

arrow_forward
Step 1: Introduction
It looks like you've provided a Java program that calculates and prints the Fibonacci sequence using a recursive approach. The program defines a class named "Fibonacci" with a recursive method "F" to calculate the Fibonacci number for a given input "N." The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1.
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- How do I code: public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int lastIndex) public static double average(int[] arr) in java?arrow_forward1. When you run the following code, what would happen?public class Question1 {public static void main(String arg[]){int i;int [] A = new int[10];int count = 0;int temp = 10;for (i=0; i < A.length; i++)if (A[i] < temp) count++;System.out.println(count);}}(a) It finds the smallest value and stores it in temp.(b) It finds the largest value and stores it in temp.(c) It counts the number of elements equal to the smallest value in list.(d) It counts the number of elements in list that are less than temp.arrow_forwardJava Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - Given the following code, the output is __. class Sample{ public static void main (String[] args){ try{ System.out.println(5/0);}catch(ArithmeticException e){ System.out.print("Divide by zero????");}finally{ System.out.println("5/0"); } }} A. Divide by zero????B. 5/0C. Divide by zero????5/0D. 5/0Divide by zero????E. "5/0" Part 2 - Given the following code, the output is __. try{ Integer number = new Integer("1"); System.out.println("An Integer instance.");}catch (Exception e){ System.out.println("An Exception.");} A. An Integer instance.B. An Exception.C. 1D. Error: ExceptionE. None of the optionsarrow_forward
- Write a recursive method in java that sums all values between s and n inclusive /* assume s is less than or equal to n to start */ public static int sum(int s, int n) { }arrow_forwardpublic static int test(int n, int k) { if (k == 0 || k == n) { return 1; } else if (k>n) { return 0; } else { return test(n-1, k-1) + test(n-1, k); } ww For each of the following calls, indicate the output that is produ test(7,5); test(6,4); test(4,5); test(8,3); test(5,5);arrow_forwardJava - public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); } What is printed by the call test_b(6)?arrow_forward
- Determine the output of the following code. public class MysterySplit{public static void main(String [ ] args){String myString = "Who likes chocolate candy for Halloween?";String [ ] words = myString.split("\\s");for (int i = 0; i < words.length; i++){String threeWords;if (i == words.length - 1)threeWords = words[i];else if(i == words.length - 2)threeWords = words[i] + " " + words[i + 1];elsethreeWords = words[i+2] + " " + words[i + 1] + " " + words[i];System.out.println(threeWords);}}}arrow_forwardConsider the following Java method. void modifyDNA ( String dna) { int [] frequency = { 0, 0, 0, 0, 0 }; for (int i = 0; i < dna. length (); i++) { switch (dna.charAt (i)) { case 'A': frequency [0]++; ngular Snip break ; case 'T': frequency [1]]++; case 'C': frequency [2]++; break ; case 'G': frequency [3]++; default : frequency [4]++; } // HERE } If the method is called as follows, what is the expected values of the array elements when the execution reaches the comment line // HERE , when the method is executed with the parameter value "ATCGGT" ? O [1,2,1,2,2] O [1,2,3,2,2] O [1,2,3,2,0] O None of the abovearrow_forwardimport java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int n = scnr.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scnr.nextInt(); } for (int i = n - 1; i >= 0; i--) { System.out.print(arr[i]); if (i > 0) { System.out.print(","); } } }}arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education