0% found this document useful (0 votes)
7 views1 page

Java Lab2 Handout

The document outlines a Java lab focused on understanding variable types and the use of arithmetic and relational operators. It includes interactive activities such as a temperature converter, a shop discount calculator, and an odd/even check. Additionally, it features a quick recap of variable declarations and a prediction puzzle for evaluating expressions.

Uploaded by

MirHazar Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Java Lab2 Handout

The document outlines a Java lab focused on understanding variable types and the use of arithmetic and relational operators. It includes interactive activities such as a temperature converter, a shop discount calculator, and an odd/even check. Additionally, it features a quick recap of variable declarations and a prediction puzzle for evaluating expressions.

Uploaded by

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

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)

You might also like