Question: 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
1 a str strreplace This statement replaces all white space in the string str with a line break chara... View full answer
Get step-by-step solutions from verified subject matter experts
