Boolean operators can seem tricky at first, and it takes practice to
evaluate them correctly. Write the value (True or False) produced by each
expression below, using the assigned values of the variables a, b, and c.Try to do this without using code, but you should check yourself when you
think you’ve got it. Hint: Work from the inside out, starting with the innermost expressions, like in arithmetic.
a = False
b = True
c = False
1. b and c
2. b or c
3. not a and b
4. (a and b) or not c
5. not b and not (a or c)
6. not ( not (not b) and not ((a or b) and c))2
Given the following code that prints, “0”:
String thisOne = “What is this?”;
String thatOne = “What is this?”;
System.out.println( thisOne.compareTo( thatOne ) );
a. Modify the string(s) so that a value greater than 0 is printed, and
explain why that happened.
b. Modify the string(s) so that a value less than 0 is printed, and explain
why that happened.
(continued…)3
Boolean and integer variables and Conditionals. Write a program that
begins with three integers, x, y, and z. Define a boolean variable
isOrdered whose value is true if the three values are either in strictly
ascending order (x < y < z) or in strictly descending order (x > y > z), and false otherwise. Print out the variable isOrdered
using System.out.println(isOrdered).
x = 10, y = 17, and z = 49
true
x = 40, y = 30, and z = 12
true
x = 10, y = 30, and z = 12
false
4
Pop up a window for a user to enter text. The display should prompt the
user to enter their name. For our purposes the code to capture this input
should be:
import javax.swing.JOptionPane;
String input = JOptionPane.showInputDialog(
“USER PROMPT”);
If the user does not enter any text display the error message:
No name was entered.
If the user enters a name display (using the name they entered):
Hello NAME!
If the user enters “Dr. Kelley” display:
Look how excellent this code is Dr. Kelley!
If the user enters 60 characters or more display:
That is too long to be a name.
Each program must include (in a comment) your name, the date, and the
course information. They may contain other comments.
2, Assignment, CS152
[SOLVED] Assignment 2 cs152
$25
File Name: Assignment_2_cs152.zip
File Size: 169.56 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.