Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.Suppose x and y are variables of type double . Write a Java code fragment that sets y to x if x is positive and

4.Suppose x and y are variables of type double. Write a Java code fragment that sets y to x if x is positive and to 0 otherwise.

5.Suppose x and y are variables of type double. Write a code fragment that sets y to the absolute value of x without calling the Math.abs function. Use an if statement.

6.Describe why it is more difficult to compare floating-point numbers than integers. Write Java code fragments to test

whether an integer n equals 10 and

whether a floating-point number x is approximately equal to 10

7.It is easy to confuse the = and == operators. Write a test program containing the statement

if (floor = 13)

What error message do you get? Write another test program containing the statement

count == 0;

What does your compiler do when you compile the program? 8.Each square on a chess board can be described by a letter and number, such as g5 in this example: image text in transcribed The following pseudocode describes an algorithm that determines whether a square with a given letter and number is dark (black) or light (white).

If the letter is an a, c, e, or g: If the number is odd: color = "black" Else: color = "white" Else: If the number is even: color = "black" Else: color = "white"

Trace this algorithm by making a table such that:

The table headers are the variables (one column per variable)

The first row shows the initial (assumed) values of the variables

Each following row shows a value change in a variable

9.Give a set of four test cases for the algorithm from question 8 that covers all branches.

Show transcribed image text

87654321 9 87654321

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

Step: 3

blur-text-image

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions