Question
Java Please comment within the program as to what is going on or what your thought process was. Thank you -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /****************************************************************************** * Compilation: javac
Java
Please comment within the program as to what is going on or what your thought process was. Thank you
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****************************************************************************** * Compilation: javac Stopwatch.java * Execution: java Stopwatch n * Dependencies: none * * A utility class to measure the running time (wall clock) of a program. * * % java8 Stopwatch 100000000 * 6.666667e+11 0.5820 seconds * 6.666667e+11 8.4530 seconds * ******************************************************************************/ /** * The {@code Stopwatch} data type is for measuring * the time that elapses between the start and end of a * programming task (wall-clock time). * * See {@link StopwatchCPU} for a version that measures CPU time. * For additional documentation, * see Section 1.4 of * Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. * * @author Robert Sedgewick * @author Kevin Wayne */ public class Stopwatch { private final long start; /** * Initializes a new stopwatch. */ public Stopwatch() { start = System.currentTimeMillis(); } /** * Returns the elapsed CPU time (in seconds) since the stopwatch was created. * * @return elapsed CPU time (in seconds) since the stopwatch was created */ public double elapsedTime() { long now = System.currentTimeMillis(); return (now - start) / 1000.0; } /** * Unit tests the {@code Stopwatch} data type. * Takes a command-line argument {@code n} and computes the * sum of the square roots of the first {@code n} positive integers, * first using {@code Math.sqrt()}, then using {@code Math.pow()}. * It prints to standard output the sum and the amount of time to * compute the sum. Note that the discrete sum can be approximated by * an integral - the sum should be approximately 2/3 * (n^(3/2) - 1). * * @param args the command-line arguments */ public static void main(String[] args) { int n = Integer.parseInt(args[0]); // sum of square roots of integers from 1 to n using Math.sqrt(x). Stopwatch timer1 = new Stopwatch(); double sum1 = 0.0; for (int i = 1; i
Copyright 20002019, Robert Sedgewick and Kevin Wayne. Last updated: Thu Aug 11 08:17:23 EDT 2022.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EfficientPrimeNumbers.java public class EfficientPrimeNumbers { public static void main(String[] args) { int n = 8000000; // A list to hold prime numbers java.util.Listlist = new java.util.ArrayList(); int count = 0; // Count the number of prime numbers int number = 2; // A number to be tested for primeness int squareRoot = 1; // Check whether number ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PrimeNumbers.java public class PrimeNumbers { public static void main(String[] args) { int n = 8000000; int count = 0; // Count the number of prime numbers int number = 2; // A number to be tested for primeness // Repeatedly find prime numbers while (number
; and You will also need the Jata type. Your program should print a table like this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started