ANSWERS FOR PRACTICE MIDTERM A 1.a. The Java compiler takes the Java source code and converts it into binary Byte Code. This Byte Code is more efficient to run than source code and can be executed on any machine for which a Java interpreter is available. 1.b. Structured programming is the idea that all programs can be written using three constructions: sequence, decision (if..else), and repetition (while). No go to statements are needed, which makes the code much easier to understand. 1.c. The address of a variable is the actual location in the computers memory where the value of the variable is stored. 1.d. An assignment operator is an operator that changes the value of a variable by assigning a new value to it. This new value can be independent of the original value as in the case of =, or the new value can depend on the original value as in the case of +=, -=, *=, /=, %=, ++, --. 2. When you run this Java program, the loop continues forever. It turns out that Java does not check for overflow in integers; the high order bits are just lost, much like when an odometer rolls over to 100,000 miles: it goes back to 0. When the "binary odometer" of a Java 4-byte int gets set to 4,294,967,296, which is 1 00000000 00000000 00000000 00000000 in binary, it rolls over to 0. This is because an int can only hold 32 bits. The 33rd leftmost bit is lost. As a result, the values printed are 2 4 16 256 65536 0 0 0 ..... 3. public class Main { public static void main(String[] args) { String word; char letter; int i, vowelCount = 0; word = JOptionPane.showInputDialog("Enter a string.")); word = word.toUpperCase(); for(i = 0; i <= word.length() - 1; i++) { letter = word.charAt(i); if(letter=='A' || letter=='E' || letter=='I' || letter=='O' || letter=='U') { vowelCount++; } } System.out.println("The number of vowels is " + vowelCount + "."); } } 4. public class Main { public static void main(String[] args) { int a, b, c, d, s, t, result; a = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); b = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); c = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); d = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); s = Math.min(a, b); t = Math.min(c, d); result = Math.min(s, t); System.out.println("The minimum is " + result + "."); s = Math.max(a, b); t = Math.max(c, d); result = Math.max(s, t); System.out.println("The maximum is " + result + "."); } }