Exercise On Lesson 10 - p1
Exercise On Lesson 10 - p1
Exercise on Lesson 8
In problems1 – 5 assume the following: int z = 23, x = -109;
double c = 2345.19, v = 157.03; boolean a = false, s = true;
1. booleangus=(x>0)&&(c==v); System.out.println(!gus);
2. System.out.println(a | | s);
5. 5. System.out.println( z!=x );
In order given on the book: (!a &&b) false, true, false, false,
(a||!b) False, true, true, true
7. Assume b, p, and q are booleans. Write code that will assign to b the result of AND- ing p and
q.
b=p&&q;
boolean w=(x>0) || (y==z);
8. Assign to the boolean variable w the result of OR-ing the following two things: A test to see
if x is positive: A test to see if y equals z:
10. Write a test that will return a true if a is not equal to b. Assume a and b are integers.
Store the result in boolean kDog.
Boolean kDog=a!=b
1. Write the answer to #10 another way. (?? L’ho scritto io, da verificare )
if (a!=b) {
kDog = true
}
else {
kDog = false
}
2. What is the Java operator for boolean AND-ing?
||
Exercise on Lesson 9
Use the following code for problems 1 – 10 and give the value of true_false for each: int i = 10, j = 3;
boolean true_false;
5. true_false=( (i>j)&&(j==0) );
6. true_false=( (j<50)||(j!=33) );
7. true_false=( !(j>=0)||(i<=50) );
11. Write a statement that will store a true in boolean b if the value in the variable m is 44 or less.
12. Write a statement that will store a false in boolean b if the value in r is greater than 17.
13. What is returned by the following expression? (Recall that the precedence order of logical
operators is !, &&, and finally | |.)
!( (2>3) | | (5= =5) && (7>1) && (4<15) | | (35<=36) && (89!=34) )
17. Write a statement that will store a false in boolean b if the value in g is not equal to 34.
18. Write a statement that will store a true in boolean b if integer k is even, false if it is odd.
19. Write a program that inputs a String from the keyboard after the prompt, “Enter your
password”. If it’s entered exactly as “XRay”, printout “Password entered successfully.”;
otherwise, have it printout “Incorrect password.”
20. What is output by the following “nested ifs” code? int k = 79;
if (k>50) {
} else {
if (k>30) System.out.println(“Three”);
else
System.out.println(“Four”);
Exercise on Lesson 10
1. What are the primary three permissible data types to use for x in the following? switch (x){ . .
.}