Sunteți pe pagina 1din 8

Test Through Lesson 3 (Use pencils!

Name ____________________________ Station ______

1. Write two lines of code where the first prints hello, the second prints World, and the net result is
that they print together exactly as follows:
hello World

2. Suppose you want to document your program with the following text. Modify this line of text so that
it can legally reside in your program as a comment.
Program author: Ms. Fefe LaFu
3. The following block of text is to be considered a comment. Rather than commenting out each line of
text, modify the text using the block technique of commenting out the text.
Name: Mesut zil
Date: Oct. 15, 1988
School: MCSM
4. Write the following number in a more conventional way as would be done in a math class.
7.803E-12
5. In the following two lines of code, state which line is initializing and what that means.
int siv;
siv = 14;
6. Suppose we wish to create a variable name using the words distance to line. Choose the most
conventionally acceptable way to name this variable.
Distance_To_Line
distancetoline
distance To Line
DISTANCETOLINE
distanceTOline
distanceToLine
7. Place a check mark next to all legal variable names (even if not conventionally acceptable)?
Arrow
bookX
dinner bell

public
x
XCORD

integer
xx
myName

double
dinner_bell
23Yg

camera
dinnerbell
d39

8. What is the meaning of a floating point number?


9. What variable type would you use to store your schools name?
10. Whats wrong (if anything) with this line of code?
integer ii = 64.00;
11. Whats wrong (if anything) with this line of code according to our current understanding?
Double dur = 102;
12. Whats wrong (if anything) with this line of code?
string myNumber = 122.809;
13. Rewrite the following line of code as two separate lines of code.
double dd = 1000.56;

14. Suppose you have two Strings, str1 and str2. Write a line of code that concatenates these two
strings (with str2 coming first) and assign the result to the String p.
15. Suppose that #14 above was done correctly. What would the following print assuming that str1 =
Hello and str2 = world?
System.out.println(p);

16. Using str1 and str2 as defined in 17 and 18 above, concatenate them and assign to String h so that
the result will be Hello world.
17. Which character is at the 6th Change this index in Hi there?
18. What is output by the following code?
String s = soccer Boots;
int theLen = s.length( );
System.out.println(theLen);
String str1 = s.substring(5);
System.out.println(str1);
String str2 = s.substring(5,9);
System.out.println(str2);
String str3 = s. toLowerCase( )
System.out.println(s);
19. Write a line of code that will print The file Names.java is in c:\leet\.
20. What is output by the following code?
System.out.println(klm\nopqrs\tu);
21. Write code that will determine the number of characters in the String v and then print, The String
has 22 characters. The 22 part is just an example. Use the length( ) method to print the 22 (or
whatever it might be actually be for v).
22. What will be the value of jy?
String bj = Oh my goodness!
int p6 = 6;
String jy = bj.substring( p6-6, p6 );
23. What will be the output of the following code?
String s = Kitty cat;
int kc_len = s.length( );
String ms = s.substring(kc_len-2);
System.out.println(ms);
24. What is the meaning of concatenating two strings? (Answer in a complete sentence.)
25. Give the names of two methods of the String class.

Test Through Lesson 3 (Use pencils!)

Name ____________________________ Station ______

1. Write two lines of code that will cause Computer Science to be printed on the screen.
Change this

2. The following block of text is to be considered a remark. Rather than putting a double slash in front
of each line of text, modify the text using the block technique of commenting out the text.
Name: Lori Petty
Date: Oct 14, 1963
School: MCSM
3. Suppose you want to document your program with the following text. Modify this line of text so that
it can legally reside in your program as a comment.
Program author: Ms. Hehe Lafu
4. Write the following number from a science class in Java.
3.1893g1012
5. In the following two lines of code, state which line is declaring and what that means.
int siv;
siv = 14;
6. Suppose we wish to create a variable name using the words distance to line. Choose the most
conventionally acceptable way to name this variable.
DistanceToLine
distance-to-line
distance_to_line
Distance_To_Line
distancetoline
distance To Line
7. Place a check mark next to all legal variable names (even if not conventionally acceptable)?
Arrow
bookX
dinner bell

public
x
XCORD

integer
xx
myName

double
dinner_bell
23Yg

camera
dinnerbell
d39

8. Explain the meaning of double in Java.


9. What variable type would you use to store your age?
10. Whats wrong (if anything) with this line of code?
Int ii = 59.0;
11. Whats wrong (if anything) with this line of code?
String myNumber = 122.809
12. Whats wrong (if anything) with this line of code?
double dur = 104;
13. Rewrite the previous statement as two separate lines of code.

14. Suppose you have two Strings, str3 and str4. Write a line of code that concatenates these two
strings (with str4 coming first) and assign the result to the String q.
15. Suppose that #14 above was done correctly. What would the following print assuming that str1 =
hello and str2 = World?
System.out.println(p);

16. Using str1 and str2 as defined in 17 and 18 above, concatenate them and assign to String h so that
the result will be hello World.
17. Which character is at the 5th index in Hi there?
18. What is output by the following code?
System.out.println(wvu\tsrqpo\nmlk);
19. Write a line of code that will print Enough \ from the new policy.
20. What is output by the following code?
String s = Turf shoes;
int theLen = s.length( );
System.out.println(theLen);
String str1 = s.substring(2);
System.out.println(str1);
String str2 = s.substring(2,6);
System.out.println(str2);
String str3 = s.toUpperCase( )
System.out.println(s);
21. Write code that will determine the number of characters in the String v and then print, The String
has 22 characters. The 22 part is just an example. Use the length( ) method to print the 22 (or
whatever it might be actually be for v).
22. What will be the value of jy?
String bj = Oh my goodness!
int p4 = 4;
String jy = bj.substring( p4-4, p4 );
23. What will be the output of the following code?
String s = Kitty cat;
int kc_len = s.length( );
String ms = s.substring(kc_len-2);Change this
System.out.println(ms);
24. What is the meaning of concatenating two strings? (Answer in a complete sentence.)
25. Give the names of two methods of the String class.

Test Through Lesson 3

Answer Key

1. Write two lines of code where the first prints hello, the second prints World, and the net result is
that they print together exactly as follows:
hello World
System.out.print(hello );
System.out.println(World);
2. Suppose you want to document your program with the following text. Modify this line of text so that
it can legally reside in your program as a comment.
// Program author: Ms. Fefe LaFu
3. The following block of text is to be considered a comment. Rather than commenting out each line of
text, modify the text using the block technique of commenting out the text.
/* Name: Mesut zil
Date: Oct. 15, 1988
School: MCSM
*/
4. Write the following number in a more conventional way as would be done in a math class.
7.803E-12
7.803g1012
5. In the following two lines of code, state which line is initializing and what that means.
int siv;
siv = 14;
// stores the integer 14 into variable named siv
6. Suppose we wish to create a variable name using the words distance to line. Choose the most
conventionally acceptable way to name this variable.
Distance_To_Line
distancetoline
distance To Line
DISTANCETOLINE
distanceTOline
distanceToLine
7. Place a check mark next to all legal variable names (even if not conventionally acceptable)?
Arrow
bookX
dinner bell

public
x
XCORD

integer
xx
myName

double
dinner_bell
23Yg

camera
dinnerbell
d39

8. What is the meaning of a floating point number?


Its basically a decimal number. (Technically, its a number in the form int g2exp .)
9. What variable type would you use to store your schools name? String
10. Whats wrong (if anything) with this line of code?
integer ii = 64.00;
// Theres no value type integer, only int. Also, cannot store floating point
// number in an int variable.
11. Whats wrong (if anything) with this line of code according to our current understanding?
Double dur = 102;
// Case matters. Should be double.
12. Whats wrong (if anything) with this line of code?
string myNumber = 122.809;
// Should be String
13. Rewrite the following line of code as two separate lines of code.
double dd = 1000.56;
double dd;
dd = 1000.56;
14. Suppose you have two Strings, str1 and str2. Write a line of code that concatenates these two
strings (with str2 coming first) and assign the result to the String p.
String p = str2 + str1;

15. Suppose that #14 above was done correctly. What would the following print assuming that str1 =
Hello and str2 = world?
System.out.println(p);
worldHello
16. Using str1 and str2 as defined in 17 and 18 above, concatenate them and assign to String h so that
the result will be Hello world.
String h = str1 + + str2;
17. Which character is at the 6th index in Hi there?
r
18. What is output by the following code?
12
r Boots
r Bo
soccer Boots

String s = soccer Boots;


int theLen = s.length( );
System.out.println(theLen);
String str1 = s.substring(5);
System.out.println(str1);
String str2 = s.substring(5,9);
System.out.println(str2);
String str3 = s.toLowerCase( );
System.out.println(s);

19. Write a line of code that will print The file Names.java is in c:\leet\.
System.out.println(The file Names.java is in \c:\\leet\\\.);
20. What is output by the following code?
System.out.println(klm\nopqrs\tu);
klm
opqrs
u
21. Write code that will determine the number of characters in the String v and then print, The String
has 22 characters. The 22 part is just an example. Use the length( ) method to print the 22 (or
whatever it might be actually be for v).
System.out.println(The String has + v.length() + characters.);
22. What will be the value of jy?
Oh my
or without the quotes

String bj = Oh my goodness!
int p6 = 6;
String jy = bj.substring( p6-6, p6 );

23. What will be the output of the following code?


String s = Kitty cat;
int kc_len = s.length( );
String ms = s.substring(kc_len-2);
System.out.println(ms);

at

24. What is the meaning of concatenating two strings? (Answer in a complete sentence.)
To concatenate is to join together the two strings to form a new string.
25. Give the names of two methods of the String class.
length(), substring(int), substring(int, int), toLowerCase(), toUpperCase(), etc.

Test Through Lesson 3

Answer Key

1. Write two lines of code that will cause Computer Science to be printed on the screen.
System.out.print(Computer );
System.out.println(Science);
2. The following block of text is to be considered a remark. Rather than putting a double slash in front
of each line of text, modify the text using the block technique of commenting out the text.
/* Name: Lori Petty
Date: Oct 14, 1963
School: MCSM
*/
3. Suppose you want to document your program with the following text. Modify this line of text so that
it can legally reside in your program as a comment.
// Program author: Ms. Hehe Lafu
4. Write the following number from a science class in Java.
3.1893E-12
3.1893g1012
5. In the following two lines of code, state which line is declaring and what that means.
int siv;
// creates a variable named siv that can store an int value
siv = 14;
6. Suppose we wish to create a variable name using the words distance to line. Choose the most
conventionally acceptable way to name this variable.
DistanceToLine
distance-to-line
distance_to_line
Distance_To_Line
distancetoline
distance To Line
7. Place a check mark next to all legal variable names (even if not conventionally acceptable)?
Arrow
bookX
dinner bell

public
x
XCORD

integer
xx
myName

double
dinner_bell
23Yg

camera
dinnerbell
d39

8. Explain the meaning of double in Java.


Its basically a type of value, with a decimal point. (Its a variable type, but 2.35 is also a double.)
9. What variable type would you use to store your age? int
10. Whats wrong (if anything) with this line of code?
Int ii = 59.0;
// Case matters; should be int. Also, cannot store floating point
// number in an int variable.
11. Whats wrong (if anything) with this line of code?
String myNumber = 122.809
// missing semicolon ; at the end
12. Whats wrong (if anything) with this line of code?
double dur = 104;
// Nothing. (Java will store ~104.0 into dur in a widening conversion.)
13. Rewrite the previous statement as two separate lines of code.
double dur;
dur = 104;
14. Suppose you have two Strings, str3 and str4. Write a line of code that concatenates these two
strings (with str4 coming first) and assign the result to the String q.
String q = str4 + str3;
15. Suppose that #14 above was done correctly. What would the following print assuming that str1 =
hello and str2 = World?
System.out.println(p);
Worldhello;

16. Using str1 and str2 as defined in 17 and 18 above, concatenate them and assign to String h so that
the result will be hello World.
String h = str1 + + str2;
17. Which character is at the 5th index in Hi there?
e
18. What is output by the following code?
System.out.println(wvu\tsrqpo\nmlk);
Wvu srqpo
mlk
19. Write a line of code that will print Enough \ from the new policy.
System.out.println(Enough \\ from the \new\ policy.);
20. What is output by the following code?
10
rf shoes
rf s
Turf shoes

String s = Turf shoes;


int theLen = s.length();
System.out.println(theLen);
String str1 = s.substring(2);
System.out.println(str1);
String str2 = s.substring(2,6);
System.out.println(str2);
String str3 = s.toUpperCase();
System.out.println(s);

21. Write code that will determine the number of characters in the String v and then print, The String
has 22 characters. The 22 part is just an example. Use the length( ) method to print the 22 (or
whatever it might be actually be for v).
System.out.println(The String has + v.length() + characters.);
22. What will be the value of jy?
String bj = Oh my goodness!
int p4 = 4;
String jy = bj.substring( p4-4, p4 );

Oh m
or without the quotes

23. What will be the output of the following code?


String s = Kitty cat;
int kc_len = s.length( );
String ms = s.substring(kc_len-2);
System.out.println(ms);

at

24. What is the meaning of concatenating two strings? (Answer in a complete sentence.)
To concatenate is to join together the two strings to form a new string.
25. Give the names of two methods of the String class.
length(), substring(int), substring(int, int), toLowerCase(), toUpperCase(), etc.

S-ar putea să vă placă și