Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

1. What is the lowest and highest possible value generated by the following expressions using the random double x = Math.abs(-5.0); System.out.println (x); double x Math.abs(-5); System.out.println (x); int x 7. In your own words, give an example of autoboxing and unboxing. 8. Write a Java expression for the

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles of Auditing and Other Assurance Services

Authors: Ray Whittington, Kurt Pany

19th edition

978-0077804770, 78025613, 77804775, 978-0078025617

More Books

Students also viewed these Programming questions