Programming(1) - Lab2
Programming(1) - Lab2
Java Programming
Variables in Java
Lab 2
Declaring (creating) Variables
To create a variable in java we follow the syntax:
Output Output
Printing variables
• Create a two variables one to store true and one to store false and print
their values to the console.
Output
ASCII Code Table
ASCII Code Example
Create a three variables to store the ASCII code for the letters A, B and C
And print them using print statement.
Output
Printing variables
Create a variable for each data type and print them each on a new line using printf statement.
Output
Create two variables to store number of items and the cost
of single item.
Then create a new variable to store the total cost of all
items and print using println:
• Number of items
• Cost per item Expected output
• Total cost
Solution
Swapping Values
Create two variables to store two integer.
Then swap the values of the two variables and print the
values before and after swapping using print statement.
Expected output
Swapping Solution
Swapping using printf()
Thanks!