Java Lab 2 – Variables & Operators
Objective: Learn variable types and use arithmetic & relational operators.
Quick Recap (Cheat Sheet) Interactive Activities (Tasks)
int a = 10;
double b = 5.5;
1. Temperature Converter
char ch = 'A'; Input Celsius (integer or double). Convert to
boolean flag = true; Fahrenheit using: F = (C * 9/5) + 32 and print with
label.
double c = 25;
double f =(c * 9.0/5.0) + 32.0;
System.out.println("F = " + f);
2. Shop Discount
Input original price (double). Apply a 10% discount
Predict & Run (Puzzle) and print the final price formatted simply:
"Final price = <value>".
int x = 5;\nSystem.out.println(x++ + ++x); // Predict the printed value (evaluate step-by-step)
double price = 1000.0;
double finalPrice = price *
Notes / Output
3. Odd/Even Check
Input an integer and print whether it is "Even" or
"Odd". Hint: use modulus operator `%`.
int n = 7; System.out.println((n % 2 == 0) ? "Even"
MK Tech – Java Lab Handout • Single-page, print-ready (A4)