Ask Question
12 August, 16:49

What is the output of the following code snippet? int f1 = 0; int f2 = 1; int fRes; System. out. print (f1 + " "); System. out. print (f2 + " "); for (int i = 1; i < 10; i++) { fRes = f1 + f2; System. out. print (fRes + " "); f1 = f2; f2 = fRes; }System. out. println (); Select one:a. 0 1 5 7 9 11 13 15 17 19b. 0 1 1 2 3 5 8 13 21 34c. 0 1 4 6 8 10 12 14 16 18d. 0 1 6 7 9 12 14 17 19 21

+3
Answers (1)
  1. 12 August, 19:03
    0
    b. 0 1 1 2 3 5 8 13 21 34

    Explanation:

    int f1 = 0; creates an integer variable named f1 and sets its value as 0 int f2 = 1; creates an integer variable named f2 and sets its value as 1 fRes; creates an integer variable with no value System. out. print (f1 + " "); prints the value of f1 (0) System. out. print (f2 + " "); prints the value of f2 (1) The for loop runs 9 times and sets the value of fRes to the sum of f1 and f2, prints fRes, changes the value of f1 to f2, and changes the value of f2 to the current value of fRes System. out. printIn () prints a new line

    The result of the loop block will be

    (0 + 1) = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55

    So, it first prints "0 1" (the value of the first 2 variables), then the result of the the loop block

    That would be 0 1 1 2 3 5 8 13 21 34 55
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the output of the following code snippet? int f1 = 0; int f2 = 1; int fRes; System. out. print (f1 + " "); System. out. print (f2 + ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers