
44-141 Computer Programming I
Exercise 01
1. How does one write a one line comment in Java?
// comment to end of line
2. How does one write a comment in Java that extends to more than one line?
/*comment*/
3. Write the single line of Java code that will display (output) the word ‘hello’ on the screen
(without the quotes).
System.out.print(“Hello”);
4. Write two lines of Java code that will display the following text on two lines.
This is the first line
This is the second line
System.out.println(“This is the first line”);
System.out.print(“This is the second line”);
5. Provide an example of the type of data that might be stored with each data type.
a) int - -1, 0, -5, 3
a) double – 3.6, -2.8
b) char – ‘a’, ‘#’,’l’
c) boolean – true or false
d) String – “Hi!”
6. Write the Java code to declare a variable named examScore that will store whole
numbers (no decimal values).
int examScore;
7. Write the Java code to assign the value 10 (an integer) to the declared variable named
examScore.
examScore=10;
8. Write the Java code to declare and assign the value 10.5 (a double dateype) to a
variable named price.
double price=10.5;
9. Write the Java code to display the contents of the variable examScore to the
monitor.
System.out.print(examScore);
10. Write the Java code to display the contents of the variable price to the monitor.
System.out.print(price);
Challenge Problems (You are not required to complete the challenge problems):
1. Write one line of Java code that will display the following text on two lines as
shown below.
This is the first line
This is the second line
System.out.print(“This is the first line\nThis is the second line”);
2. Write one line of Java code that will display the following text on one line with a
tab character separating the text as shown below.
This line contains a tab character