0% found this document useful (0 votes)
146 views2 pages

PP02 Tutorial01

The document provides examples of Java code snippets to demonstrate programming principles including displaying text, prompting for and displaying user input, variable assignment and arithmetic operations, and output formatting. It contains 13 sections with examples and questions about Java code.

Uploaded by

2gc99d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views2 pages

PP02 Tutorial01

The document provides examples of Java code snippets to demonstrate programming principles including displaying text, prompting for and displaying user input, variable assignment and arithmetic operations, and output formatting. It contains 13 sections with examples and questions about Java code.

Uploaded by

2gc99d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 ;
b.result= z * 2 ;
c. result = y / x ;
d.result= 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;

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
;

(x, y, z) = (a, b, c);

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. 


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 


You might also like