When you execute the CompareLoopTimes program shown in Figure 6-29, you will occasionally see a negative number
Question:
When you execute the CompareLoopTimes program shown in Figure 6-29, you will occasionally see a negative number output when the nanoseconds values retrieved fall in different seconds. Modify the program to fix this problem, and save the file as CompareLoopTimes3.java. (Hint: It might take hundreds or thousands of executions for you to “catch” the program near the end of a second in order to test your modifications. For testing purposes, you can assign values to the start and stop times instead of retrieving them from the LocalDateTime class.)
Transcribed Image Text:
import java.time.*; public class CompareloopTimes { public static void main (String[] args) { int startTime, endTime; final int REPEAT = 100_000; final int FACTOR = 1_000_000; LocalDateTime now; now = Loca1DateTime.now(); startTime = now.getNano(%; for (int x = 0; x <= REPEAT; ++x) for (int y = 0; y <= REPEAT; ++y); now = LocalDateTime.now (); endTime = now.getNano (); System.out.println("Time for loops starting from 0: "+ ((endTime - startTime) / FACTOR) + " milliseconds"); now = LocalDateTime.now (); startTime = now.getNano(); for (int x = REPEAT; x >= 0; --x) for (int y = REPEAT; y >= 0; --y); now = LocalDateTime.now(); endTime = now.getNano (); System.out.println("Time for loops ending with 0: ((endTime - startTime) / FACTOR) + " milliseconds"); } } Figure 6-29 The CompareLoopTimes application
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 73% (15 reviews)
import javatime public class CompareLoopTimes3 public static void mainString args int star...View the full answer
Answered By
Atuga Nichasius
I am a Highly skilled Online Tutor has a Bachelor’s Degree in Engineering as well as seven years of experience tutoring students in high school, bachelors and post graduate levels. I have a solid understanding of all learning styles as well as using asynchronous online platforms for tutoring needs. I individualise tutoring for students according to content tutoring needs assessments.
My strengths include good understanding of all teaching methods and learning styles and I am able to convey material to students in an easy to understand manner. I can also assists students with homework questions and test preparation strategies and I am able to help students in math, gre, business , and statistics
I consider myself to have excellent interpersonal and assessment skills with strong teaching presentation verbal and written communication
I love tutoring. I love doing it. I find it intrinsically satisfying to see the light come on in a student's eyes.
My first math lesson that I taught was when I was 5. My neighbor, still in diapers, kept skipping 4 when counting from 1 to 10. I worked with him until he could get all 10 numbers in a row, and match them up with his fingers.
My students drastically improve under my tutelage, generally seeing a two grade level improvement (F to C, C to A, for example), and all of them get a much clearer understanding!
I am committed to helping my students get the top grades no matter the cost. I will take extra hours with you, repeat myself a thousand times if I have to and guide you to the best of my ability until you understand the concept that I'm teaching you.
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
1. Write a Java program that calls a method called reverse3 that accepts an ArrayList of integer values as a parameter and reverses each successive sequence of three values in the list. If the list...
-
Great Slate, a medium-sized slate flooring and finishes company, is located in Castleton, VT. Great Slate maintains more than a thousand customers who order slate products as often as weekly or as...
-
The water usage in a small town is measured in gallons per hour. A plot of this rate of usage is shown in Figure 6 for the hours midnight through noon for a particular day. Estimate the total amount...
-
Data Set 14 in Appendix B lists highway fuel consumption amounts (mi/gal) for cars categorized by size (small, midsize, large). If we use those highway fuel consumption amounts arranged into the...
-
Replacement times for TV sets are normally distributed with a mean of 8.2 years and a standard deviation of 1.1 years (based on data from "Getting Things Fixed," Consumer Reports). Estimate the...
-
Find each product or quotient. Simplify the answers. V-54 27
-
Compare and contrast assemblers, compilers, interpreters, and virtual machines.
-
Mikita Inc. experienced the following accounting events during its 2014 accounting period: 1. Paid cash to settle an account payable. 2. Collected a cash advance for services that will be provided...
-
The height of a person above the ground on a Ferris wheel is given by the function: 1 H (t) = 9 sin - 20 +12 2 where H(t) is the height in metres of the person t seconds after taking a seat on the...
-
The cellphone brands owned by a sample of 20 respondents were: Apple, Samsung, Appel, Nokia, Blackberry, HTC, Apple, Samsung, HTC, LG, Blueberry, Samsung, Samsung, APPLE, Motorola, Apple, Samsung,...
-
Which of the following has the lowest precedence? a. < b. == c. && d. ||
-
a. Write an application that counts by three from 3 through 300 inclusive, and that starts a new line after every multiple of 30 (30, 60, 90, and so on). Save the file as CountByThrees.java. b....
-
A paper factory dumps polluting chemicals into the Snake River. Thousands of citizens live along the river, and they bring suit, claiming damages. You are asked by the judge to testify at the trial...
-
What are the four basic groupings on an income statement?
-
What rules there are to the same audit team being assigned to a firm year after year. Do you think that may influence the audit?
-
What sddctea document provides the guidance on how to properly tiedown vehicles and equipment for rail loading and movement?
-
How would the same influence tactic(s) you discussed for Week 6 Positive Influence work for the New Belgium Brewing Company?
-
Listed the three classification categories of bond investment and 2 categories of equity investment identify the following (NO debit or credit) 1) what value is reported on the balance sheet at the...
-
How does the audit of access rights management in the payroll cycle affect the audit of other transaction cycles?
-
Explain the term "Equivalent Units". Why are they calculated in process costing? [4 Marks] [minimum 350 words]
-
Which assignment is correct in Java? a. int value = (float) 4.5; b. float value = 4 (double); c. double value = 2.12; d. char value = 5c;
-
Which assignment is correct in Java? a. double money = 12; b. double money = 12.0; c. double money = 12.0d; d. All of the above are correct.
-
Which assignment is correct in Java? a. char aChar = 5.5; b. char aChar = W; c. char aChar = '*'; d. Two of these are correct.
-
A rhino is charging at you, so decide to sedate it with a tranquilizer gun angled at 40 as shown above. The tranquilizer gun can reach a horizontal distance of 49 m when angled at 45. (Assume ideal...
-
What is the definition of motivation and how can the chef foster an environment of motivation in the kitchen? What methods can a chef implement to motivate the kitchen team? What factors contribute...
-
Article Review Read the article. Link is given below: https://www.projecttimes.com/articles/avoid-the-top-three-real-causes-of-scope-creep.html Post your thoughts on this article, add references if...
Study smarter with the SolutionInn App