Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.Find the errors in the following if statements: if x > 0 then System.out.print(x); if (1 + x > Math.pow(x, Math.sqrt(2)) { y = y

2.Find the errors in the following if statements:

if x > 0 then System.out.print(x);

if (1 + x > Math.pow(x, Math.sqrt(2)) { y = y + x; }

if (x = 1) { y++; }

3.What does each of these code fragments print?

int n = 1; int m = -1; if (n else { System.out.print(m); }

int n = 1; int m = -1; if (-n >= m) { System.out.print(n); } else { System.out.print(m); }

double x = 0; double y = 1; if (Math.abs(x - y) else { System.out.print(y); }

double x = Math.sqrt(2); double y = 2; if (x * x == y) { System.out.print(x); } else { System.out.print(y); } // For part (d), write down an answer based on the logic. // Then, type (or copy-paste) the code into the main method // of a Java program and compile and execute. // What result do you get? Why do you think this happens?

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.

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

LO1 Explain how the workforce is changing in unpredicted ways.

Answered: 1 week ago

Question

LO6 List the components of job descriptions.

Answered: 1 week ago