1. What is the lowest and highest possible value generated by the following expressions using the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. What is the lowest and highest possible value generated by the following expressions using the random method? Expression Math.random() Math.random()* 3 Lowest Possible Value (int) (Math.random ()*5) + 3 (int)Math.random() *4 + 5 (int) (Math.random() *50) (int) (Math.random()*8) + 1 (int) (Math.random () *10) + 2 (Math.random() * 10) + 2 (int) Math.random()* 10+ 2 2. Let's flip the problem. This time write the Java expression that would generate the range of values: Expression Highest Possible Value 3 Lowest Possible Value Note: The following generate a range of integer (int) values: Expression int x Math.abs (-5); System.out.println (x); int x Math.abs (-5.0); System.out.println (x); 1 2 0 (int) (Math.random() * -8) -4 Note: The following generate a range of decimal (double) values: 0 1 -5 0 3 Highest Possible Value 10 10 2 -2 4 0.2499999999 Math.random() * 0.5 + 3 0.9999999999 3.4999999999 3. Why is it difficult to write an expression that would generate a random double from 0 to 3.50000000? Console output if valid: 5 11.99999999 4. Write the console output if the statement is valid. Explain the existence of any compiler (syntax) errors. Explanation of compiler errors if not valid: double x = Math.abs (-5.0); System.out.println (x); double x Math.abs (-5); System.out.println (x); int x= Math.pow (5, 2); System.out.println (x); double x = Math.pow (2, 5); System.out.println (x); int x (int) Math.pow (2, 3); System.out.println(x); double x Math.sqrt (9); System.out.println (x); int x= Math.sqrt (100); System.out.println (x); Compiler Error 5. Reflect on the problems you just completed. Explain possible issues with using the Math methods from that experience: 6. Write the console output if the statement is valid. Explain the existence of any compiler (syntax) errors. Expression Integer a = new Integer (42) ; System.out.println (a.intValue () ); int a 42; System.out.println (a); int a 42; System.out.println (a.intValue () ); Integer a new Integer (42); System.out.println (a); Integer a 42; System.out.println (a.double Value ()); Double b = 42.0; System.out.println (b.doubleValue ()); Double b = 42.0; System.out.println (b); teger c 2; int number = c; System.out.println (c); int x = Math.sqrt (100); System.out.println (x); Math's pow method returns a double. The variable x is an integer, and Java will not implicitly cast a double to an integer. Console output if valid: errors if not valid: Explanation of compiler 2 Compiler Error The variable a is a primitive type, and can't invoke a method. This works fine. Java magically unboxes the Integer c into a primitive int number. 7. In your own words, give an example of autoboxing and unboxing. 8. Write a Java expression for the following algebraic expressions: x² - y² + |x-yl -b + √2ac |2a| 2b4 2-a 1. What is the lowest and highest possible value generated by the following expressions using the random method? Expression Math.random() Math.random()* 3 Lowest Possible Value (int) (Math.random ()*5) + 3 (int)Math.random() *4 + 5 (int) (Math.random() *50) (int) (Math.random()*8) + 1 (int) (Math.random () *10) + 2 (Math.random() * 10) + 2 (int) Math.random()* 10+ 2 2. Let's flip the problem. This time write the Java expression that would generate the range of values: Expression Highest Possible Value 3 Lowest Possible Value Note: The following generate a range of integer (int) values: Expression int x Math.abs (-5); System.out.println (x); int x Math.abs (-5.0); System.out.println (x); 1 2 0 (int) (Math.random() * -8) -4 Note: The following generate a range of decimal (double) values: 0 1 -5 0 3 Highest Possible Value 10 10 2 -2 4 0.2499999999 Math.random() * 0.5 + 3 0.9999999999 3.4999999999 3. Why is it difficult to write an expression that would generate a random double from 0 to 3.50000000? Console output if valid: 5 11.99999999 4. Write the console output if the statement is valid. Explain the existence of any compiler (syntax) errors. Explanation of compiler errors if not valid: double x = Math.abs (-5.0); System.out.println (x); double x Math.abs (-5); System.out.println (x); int x= Math.pow (5, 2); System.out.println (x); double x = Math.pow (2, 5); System.out.println (x); int x (int) Math.pow (2, 3); System.out.println(x); double x Math.sqrt (9); System.out.println (x); int x= Math.sqrt (100); System.out.println (x); Compiler Error 5. Reflect on the problems you just completed. Explain possible issues with using the Math methods from that experience: 6. Write the console output if the statement is valid. Explain the existence of any compiler (syntax) errors. Expression Integer a = new Integer (42) ; System.out.println (a.intValue () ); int a 42; System.out.println (a); int a 42; System.out.println (a.intValue () ); Integer a new Integer (42); System.out.println (a); Integer a 42; System.out.println (a.double Value ()); Double b = 42.0; System.out.println (b.doubleValue ()); Double b = 42.0; System.out.println (b); teger c 2; int number = c; System.out.println (c); int x = Math.sqrt (100); System.out.println (x); Math's pow method returns a double. The variable x is an integer, and Java will not implicitly cast a double to an integer. Console output if valid: errors if not valid: Explanation of compiler 2 Compiler Error The variable a is a primitive type, and can't invoke a method. This works fine. Java magically unboxes the Integer c into a primitive int number. 7. In your own words, give an example of autoboxing and unboxing. 8. Write a Java expression for the following algebraic expressions: x² - y² + |x-yl -b + √2ac |2a| 2b4 2-a
Expert Answer:
Related Book For
Principles of Auditing and Other Assurance Services
ISBN: 978-0078025617
19th edition
Authors: Ray Whittington, Kurt Pany
Posted Date:
Students also viewed these programming questions
-
High Desert Potteryworks makes a variety of pottery products that it sells to retailers. The company's job-order costing system uses departmental predetermined overhead rates to apply manufacturing...
-
9.1 Exercise (JDK Source Code): Extract the source code of the class Math from the JDK source code ("$JAVA_HOME" "src.zip" "Math.java" under folder "java.lang"). Study how constants such as E and...
-
The diameter of a readings are and 1.12cm found to be calculate cylinder is the successive 1-15cm, 1-13 cm, 1.16cm, 1:14 cm error and measure absolute CYTOT?
-
Give the eccentricities of conic sections with one focus at the origin of the polar coordinate plane, along with the directrix for that focus. Find a polar equation for each conic section. e = 1/2, r...
-
A researcher plans to conduct an experiment testing the effect of caffeine on reaction time during a driving simulation task. A sample of n = 9 participants is selected and each person receives a...
-
A random sample of n observations is selected from a normal population to test the null hypothesis that = 10. Specify the rejection region for each of the following combinations of Ha, a, and n: a....
-
The following is the distribution of the hourly number of trucks arriving at a company's warehouse: Find the mean of this distribution, and using it (rounded to one decimal place) as the parameter...
-
All sales of Tracys Jeans and Uniforms (TJU) are made on credit. Sales are billed twice monthly, on the fifth of the month for the last half of the prior months sales and on the twentieth of the...
-
ASL Ltd's most recent earnings per share was $1.00 and it paid a dividend of $0.60 per share. You expect ASL to earn $1.10 and continue its payout ratio. Assume that you expect to sell the shares for...
-
Rio Ferinand, the owner of Ferdinand Gold Mining, is evaluating a new gold mine in Fort McMurray. Paul Pogba, the company's geologist, has just finished his analysis of the mine site. He has...
-
Assume a firm that is both a monopolist and monopsonist in gadget market in a island. Labor supply equation is W = 10 +0.1L where W is wage and L is labor. Production function is W = 10L. The demand...
-
Crave is a unique platform designed for food enthusiasts and restaurant owners. It combines review app functionality with the interactivity of a social network. Food lovers can explore diverse...
-
A 30-year bond has 10% annual coupons, a par value of $1000, and a redemption value of $1000. Coupons are invested at a nominal annual rate of 6% convertible semi-annually. X is the highest price...
-
16) You are offered an investment that will pay the following cash flows at the end of each of the next five years at a cost of $800. What is the Net Present Value (NPV) if the required rate of...
-
Solve the following linear programming problem: max x + 2y s.t. x 0 y 0 2x + y 2 x-2y+60 x + 3y 15 x-y5 y4
-
Explain How The Internal Revenue Service generally treats a limited liability company as ?
-
How relays are connected in the power system?
-
Why do bars offer free peanuts?
-
The observation of a clients physical inventory is a mandatory auditing procedure when possible for the auditors to carry out and when inventories are material. a. Why is the observation of physical...
-
What relationship exists between AICPA generally accepted auditing standards (GAAS) and the statements on Auditing standards (SASs)?
-
Describe the audit technique known as tagging and tracing. What is the purpose of the technique?
-
If a random variable has a normal distribution, what are the probabilities that it will take on a value within (a) 1 standard deviation of the mean; (b) 2 standard deviations of the mean; (c) 3...
-
Verify that (a) \(z_{0.005}=2.575\); (b) \(z_{0.025}=1.96\).
-
Given a random variable having the normal distribution with \(\mu=16.2\) and \(\sigma^{2}=1.5625\), find the probabilities that it will take on a value (a) greater than 16.8 ; (b) less than 14.9; (c)...
Study smarter with the SolutionInn App