Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. a. str = str.replace(' ', ' '); b. i = str.indexOf(the); c. i = str.indexOf(the, str.length() / 2); d. i = str.compareTo(the); if (i


1.


a. str = str.replace(' ', ' ');

b. i = str.indexOf(“the”);

c. i = str.indexOf(“the”, str.length() / 2);

d.

i = str.compareTo(“the”);

if (i = 0) {

count ++;

}


System.out.println(count);



p. 279

1.

1) And (&&)

2) Or (||)

3) Not (!)


2.


P

Q

P Or Not Q

True

True

True

True

False

True

False

True

False

False

False

True



3. P And Not Q = True

P would be true, and because Q is false, Not Q would be true. Because both P and Not Q are true, P and Not Q would also be true.


4.

if (x >= min && x <= max) {

System.out.println(“x is inside the bounds”);

}


if ( x < min || x > max) {

System.out.println(“x is outside the bounds”);

}


5.

if (x >= min) {

if (x <= max) {

System.out.println(“x is inside the bounds”);

}


else {

System.out.println(“x is outside the bounds”);

}

}


else {

System.out.println(“x is outside the bounds”);

}



6.

for (int i=1; i<=10; i++) {

for (int j=1; j<=10; j++) {

System.out.print(“*”);

}

System.out.println();

}


7.

assert x < 5;

The program halts if x is not less than 5, which can help to verify the value of a variable at certain places and detect errors of input or output values.


8.

A loop variant describes the changes that happen to a value inside a loop. It usually contains information about the increments or decrements of a loop and what happens to the value when it exits the loop. A loop invariant identifies the relationships between variables that remain constant throughout the iterations of a loop. Loop invariants must be true for the values that occur before and after the loop. Both loop variants and loop invariants are guides to help the user clearly view how the values change throughout the program.


Step by Step Solution

3.53 Rating (167 Votes )

There are 3 Steps involved in it

Step: 1

1 a str strreplace This statement replaces all white space in the string str with a line break chara... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Q.4. Give examples of personal power and position power

Answered: 1 week ago