Ask Question
14 November, 17:57

What will be the result of running the following code fragment? int year = 0; double rate = 5; double principal = 10000; double interest = 0; while (year < 10) { interest = (principal * year * rate) / 100; System. out. println ("Interest " + interest); }

+2
Answers (1)
  1. 14 November, 19:15
    0
    This code fragment will run an infinite loop

    Explanation:

    This output: Interest 0.0 Will be displayed infinitely. The reason is because the variable year which is initially set to 0 is never updated and as such remains true because the condition is while (year<10). So at the first iteration the statement interest = (principal * year * rate) / 100; evaluates to 0 and this line of code System. out. println ("Interest " + interest); prints Interest 0.0. At the next iteration the same evaluation and output takes place and on and on and on ... since the control variable is not changing.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What will be the result of running the following code fragment? int year = 0; double rate = 5; double principal = 10000; double interest = ...” 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