String word = "CS170 abcd"; int i = 4; int j = 20; char c = 'd';
Assuming the above declarations and assignments have been made, give a literal of the correct type that is equivalent (in the "==
" sense) to each of the following:
word.charAt(6)
'a'
c + 5
105
++i
5
j++ - i++
16
Which of the following are legal names for variables in Java?
Write a truth table for the following expression:
(P ^ Q) && (! (P || R))
P Q R P^Q P||R !(P||R) (P^Q)&&(!(P||R)) T T T F T F F T T F F T F F T F T T T F F T F F T T F F F T T T T F F F T F T F T T F F T F T F F F F F F F T F
How many times will the following print "buzz lightyear"?
public class Main { public static void main(String[] args) { int x = 0; do { x++; System.out.println("buzz lightyear"); } while (x > 0); } }
Suppose you generate a random double, x, and display it to the console. You then ask the user to type in the value he thinks will sum with this number to equal 1. Storing his response in a double, y, what is wrong with using the following code snippet as a check to see if he was correct?
if (y == 1 - x) { System.out.println("You were correct!"); } else { System.out.println("Sorry. You were incorrect."); }