Programming Practice
1. Loop practice. What will each of the following loops produce on the
screen.
A) int number=0;
do
{
number++;
System.out.println(number);
} while (number==0);
B) int x=5;
while(x<=0)
{
System.out.println(x);
}
C) for (int x=3;x>1;x--)
System.out.println(x);
D) int x=1;
do
{
System.out.println(x);
x=x+3;
}while(x<=10);
E) int x=20;
for(int counter=0;counter<=2;counter++)
g.drawOval(20,x+counter*50,40,40);
2. Identification:
A) What do we call such an expression: (number<=100)
B) What do we call such a statement: value=7;
C) In the following statement, which is the parameter?
g.setColor(Color.blue);
D)
3. True/False
A) Applets always have a main function (method).
B) The class must have the same name as the file.
C) Using braces { } to combine several statements so they are
treated as a unit is called a "compound statement."
D) Errors, detected and handled at run time, are called "exceptions."
4) Write a complete java application using a do..while loop that prints
the Fibonnaci sequence:
1 1 2 3 5 8 13 21 34 55 89
(hint: each number is the sum of the previous 2 numbers.)
*START BY WRITING AN ALGORITHM*
Click
here to return
Copyright © 1999, 2000 All Rights
Reserved