Suppose a loop should execute while x is less than the sum of two integers, a and b. The loop could be written as:while(x < a + b)// loop bodyAlthough this code fragment will run, it is not particularly efficient. In what way is it inefficient, and how could you improve the loop's performance?
What will be an ideal response?
You can improve performance by making sure the loop does not include unnecessary operations or statements. If the while loop in the problem executes 1000 times, then the expression a + b is calculated 1000 times. Instead, if you use the following code, the results are the same, but the arithmetic is performed only once:
int sum = a + b;
while(x < sum)
// loop body
You might also like to view...
Which arithmetic operations can be performed on pointers?
A) All arithmetic operations that are legal in C++ B) Multiplication, division, addition, and subtraction C) Addition , subtraction , presentiment, and post increment D) Only multiplication and addition E) None of the above
A ______ determines the capability of the mobile device, such as screen resolution, and directs browsers to CSS.
a. sprite b. viewport c. media query d. fragment identifier
You can use the Windows 10 ________ app to find videos that explain how to do things
Fill in the blank(s) with correct word
Although you can link to documents in almost any format from your web pages, it's important to keep in mind that Java documents are the only ones that your users are guaranteed to be able to access. _________________________
Answer the following statement true (T) or false (F)