creation: 07/07/06

Review of Truth Tables and De Morgan's Rules

1.       Complete the following truth table:

Operand Operand Expression
x <= y y > 100 x <= y && y > 100
F F
F T
T F
T T

Decide from the table what the value of the expression is is when `x == 150` and `y == 125`.

2.       Complete the following truth table:

Operand Operand Expression
ch >= 'a' ch <= 'z' ch >= 'a' && ch <= 'z'
F F
F T
T F
T T

Decide from the table what the value of the expression is is when `ch == 'A'`.

3.       Complete the following truth table:

Operand Operand Operand Subexpression Expression
ch >= 'a' ch <= 'z' ch == '?'ch >= 'a' && ch <= 'z'(ch >= 'a' && ch <= 'z') || ch == '?'
F F F
F F T
F T F
F T T
T F F
T F T
T T F
T T T

Decide from the table what the value of the expression is is when `ch == 'x'`.

4.       Is `!A && B` equivalent to `A || !B`   ?   Complete the table to find out.

Operand Operand Subexpression Subexpression Expression Expression
A B !A !B !A && B A || !B
F F
F T
T F
T T

The two expressions are equivalent if the T/F values in the last two columns are the same.

Now use De Morgan's Rule:

```!(A && B) is equivalent to `!A || !B`
```

to rewrite `!A && B`.

5.       You wish to purchase a certificate of deposit, but only if the interest rate is greater than three percent and the minimum deposit is less than 10000. Fill in the blanks.

```if ( interest  3  minimum  10000)
else
System.out.println("Reject this CD");
```

Rewrite the above fragment so that it fits the following.

```if ( interest  3  minimum  10000)
System.out.println("Reject this CD");
else
```

(The first program fragment is probably the best way to write this.)

6.       A program is searching for books with a call number that starts "QA" published between 1990 and 1995 (inclusive) with the word "web" in the title. Assume that the attributes of a book are accessed by `book.getTitle()`, `book.getDate()`, and `book.getCall()`. Recall that `indexOf( String sub )` returns the integer index of the substring, or -1 if the substring is not found.

```if ( book.getCall().indexOf("QA") 0
book.getDate().  1990
book.getDate().  1995
book.getTitle().indexOf("Web")  0)

System.out.println( book.getCall(), book.getTitle() );
```

(The first program fragment is probably the best way to write this.)

End of the Exercise. If you want to do it again, click on "Refresh" in your browser window. Click here to go back to the main menu.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://book.huihoo.com/introduction-to-computer-science-using-java-5.0-version/Notes/chap40B/fillBlankCh40B.html", "fetch_time": 1537601158000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2018-39/segments/1537267158205.30/warc/CC-MAIN-20180922064457-20180922084857-00255.warc.gz", "warc_record_offset": 37740801, "warc_record_length": 2777, "token_count": 697, "char_count": 2437, "score": 3.734375, "int_score": 4, "crawl": "CC-MAIN-2018-39", "snapshot_type": "latest", "language": "en", "language_score": 0.7408565878868103, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00042-of-00064.parquet"}