|
|
(5 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
− | {{Template:1010Topic|Chapter_TOC=[[Control Structures]]|Introduction=Insert intro here}} | + | {{Template:1010Topic |
− | | + | |Chapter_TOC=[[Control Structures]] |
− | ==Review Questions and Exercises== | + | |Body= |
− | The solutions to these exercises can be found [[Control Structures Solutions|here]].
| + | ==Review Questions== |
− | | + | Programming-A-Day questions |
− | ===Review Questions===
| + | #[[Days In A Month|Days In A Month]] |
− | #Name the 3 different logical operators. What are the benefits of using logical operators? | + | #[[The Labyrinth|The Labyrinth]] |
− | #What is the proper way in Java to compare strings? Why? | + | #[[Know Your Standards|Know Your Standards]] |
− | #What are the results of the following logical operations? | + | #[[Letter Grade Conversion|Letter Grade Conversion]] |
− | ## 'a' != 'b'
| + | }} |
− | ## (127-3*9) >= (97+8/4)
| + | |
− | ## "Hello" == "Hello"
| + | |
− | #Write the truth table for the expression (X || Y) && Z
| + | |
− | | + | |
− | | + | |
− | ===Exercises===
| + | |
− | 1. Look at the code below. Clean it up so it uses the proper logical operators and proper use of if-else's.
| + | |
− | | + | |
− | <PRE>
| + | |
− | if (x == 1)
| + | |
− | {
| + | |
− | if (y == 1)
| + | |
− | {
| + | |
− | if (!!!!true)
| + | |
− | {
| + | |
− | System.out.println("X and Y are 1!");
| + | |
− | }
| + | |
− | }
| + | |
− | }
| + | |
− | if (x == 2)
| + | |
− | {
| + | |
− | System.out.println("X is 2!");
| + | |
− | }
| + | |
− | if (x < 1)
| + | |
− | {
| + | |
− | System.out.println("X is under 1 or over 2!");
| + | |
− | }
| + | |
− | if (x > 2)
| + | |
− | {
| + | |
− | System.out.println("X is under 1 or over 2!");
| + | |
− | }
| + | |
− | </PRE>
| + | |
− | | + | |
− | | + | |
− | | + | |
− | 2. Is the result of the following statement true or false?
| + | |
− | | + | |
− | <PRE>
| + | |
− | String s1 = "test";
| + | |
− | String s2 = "TEST";
| + | |
− | String s3 = "test";
| + | |
− | | + | |
− | if (!(!(s1.equals(s2) && s1.equals(s3)) || s2.equals(s3)))
| + | |
− | System.out.println("The result is true");
| + | |
− | else
| + | |
− | System.out.println("The result is false");
| + | |
− | </PRE>
| + | |
− | | + | |
− | 3. Write a program that will prompt a user to enter an integer. The program will determine whether the number is even or odd and print out the result. It will print out a different result if the number is negative. The program will continue until the user enters a 0. Also note that if the user enters a 0, the program will not print out anything other than that the program has finished.
| + | |
− | | + | |
− | 4. Write a program that will prompt the user to enter a string. The program will print out whether or not the first character is a vowel or not.
| + | |