Skip to content

Lab exercises of java

Mohamed Hassan (JOHN) edited this page Jan 30, 2025 · 4 revisions

746963652d6c6162732e706e67



Write a Java program to print the sum of 74 and 36.

Expected Output: 110


Write a Java program to divide 50 by 3 and print them on the screen.

Expected Output: 16


Write a Java program that displays the product of 25 by 5.

Expected Output: 125


Write a Java program to print the area and perimeter of a rectangle where Width = 5.5 and Height = 8.5

Area of rectangle = length Γ— width

Perimeter of a rectangle = 2 (Length + Width)

Expected Output:

Area is 5.6 * 8.5 = 47.60

Perimeter is 2 * (5.6 + 8.5) = 28.20

Write a Java program to convert temperature from 212 Fahrenheit degrees to its corresponding value in Celsius degrees.

Fahrenheit = ( 9 / 5 ) Celsius + 32

Expected Output: 212.0 degree Fahrenheit is equal to 100.0 in Celsius


Write a Java program to create a class called "Cat" with instance variables name and age. Implement a default constructor that initializes the name to "Unknown" and the age to 0. Print the values of the variables.


Write a Java program to create a class called Dog with instance variables name and color. Implement a parameterized constructor that takes name and color as parameters and initializes the instance variables. Print the values of the variables.

Clone this wiki locally