PP02 Tutorial01
PP02 Tutorial01
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
Var1 = “7689” ;
Var2 == “Hi” ;
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 ;
b.result= z * 2 ;
c. result = y / x ;
d.result= y – z ;
e. result= w % z;
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
a=5;
b=2 ;
c=3;
result = a + b * c;
System.out.println(result) ;
11. Will the following code print an error? If not, what will be the output?
a = 20 ;
b = 40 ;
c = 30 ;
System.out.print(x, y, z) ;
12. Assume the variable sales references a double value. Write a statement that
displays the value rounded to two decimal points.
number = 1234567.456
Write a Java statement that displays the value referenced by the number
variable
formatted as
1,234,567.5