Programming Principles 02 Tutorial 01
1. Write Java code to display “Hello World” and compile and execute the program
2. Write Java code to display your name and compile and execute the program
3. Write Java code that prompts the user to enter his or her height and assigns the
user’s input to a variable named height and display the same
4. Write Java code that prompts the user to enter his or her favorite color and
assigns the user’s input to a variable named color and display the same
5. Find the incorrect assignment statements from the following:
Var1 = “7689” ;
Var2 == “Hi” ;
Var3 = Hello 3 = Var4
;
6. Assume the variables result, w, x, y, and z are all integers, and that w = 5, x = 4,
y = 8, and z = 2. What value will be stored in result after each of the following
statements execute?
a. result= x+ y ;
[Link]= z * 2 ;
c. result = y / x ;
[Link]= y – z ;
e. result= w % z;
write program to demonstrate the outcome of the above program
7. Write a Java code that assigns the sum of 10 and 14 to the variable total and
display the same
8. Write a Java code that subtracts the variable down_payment from the variable
total and assigns the result to the variable due.
9. Write a Java statement that multiplies the variable subtotal by 0.15 and assigns
the
result to the variable total.
Write program to demonstrate the
outcome of the above program
10. What would the following display?
a=5;
b=2
;
c=3;
result = a + b * c;
[Link](result)
;
11. Will the following code print an error? If not, what will be the output?
a = 20
;
b = 40
;
c = 30
;
(x, y, z) = (a, b, c);
[Link](x, y, z)
;
12. Assume the variable sales references a double value. Write a statement that
displays the value rounded to two decimal points.
13. Assume the following statement has been executed:
number = 1234567.456
Write a Java statement that displays the value referenced by the number
variable
formatted as
1,234,567.5