Page 502 - Introduction to Programming with Java: A Problem Solving Approach
P. 502

                468 Chapter 11 Type Details and Alternate Coding Mechanisms Determine the output of the following code fragment:
b = a && (++c == 3.5);
a = true || (++c == 3.5);
System.out.println(a + " " + b + " " + c);
10. [after §11.10] In the Fibonacci sequence, each successive element is the sum of the two previous elements. Starting with 0 and 1, the next element is 0 􏰁 1 􏰂 1.The element after that is 1 􏰁 1 􏰂 2. The element after that is 1 􏰁 2 􏰂 3, and the one after that is 2 􏰁 3 􏰂 5, and so on. Given this declaration:
int p, q;
Provide a for loop that prints this part of the Fibonacci sequence: 1235 8
Your solution should consist of just a for loop header and then an empty statement—nothing else. By the way, we recommend that you avoid code like this for your real programs. This exercise is just for fun (fun for a hacker, anyway☺).
11. [after §11.10] A common error is to accidentally add a semicolon at the end of a loop header. Run the following main method on a computer. What is the output?
public static void main(String[] args)
{
}
int i;
int factorial = 1;
        Apago PDF Enhancer
for (i=2; i<=4; i++);
{
}
factorial *= i;
System.out.println("i = " + i + ", factorial = " + factorial);
// end main
12. [after §11.12] Note the following program. Provide a for loop that is functionally equivalent to the given do loop.
import java.util.Scanner;
public class Test
{
}
// end class Test
public static void main(String[] args)
{
}
// end main
Scanner stdIn = new Scanner(System.in);
String entry;
do
{
}
System.out.println("Enter 'q' to quit: ");
entry = stdIn.nextLine();
while (!entry.equals("q"));
13. [after §11.13] What is the Unicode hexadecimal value for the “􏰆” (infinity) symbol? Show or explain how you got your answer.



























































   500   501   502   503   504