Skip to the content.

Java > 🧑‍💻 Exercise 1

Problem 1: Arithmetic Operations

Description: Write a Java program that performs basic arithmetic operations on two given numbers.
Demonstrate the program by changing input values

Example:

Input: Declare two variables a and b of integer type and with values 15 and 5
Output: Sum: 20, Difference: 10, Product: 75, Quotient: 3, Remainder: 0

Problem 2: Area of a Rectangle

Description: Write a Java program to calculate the area of a rectangle given its length and width.
Demonstrate the program by changing input values

Example:

Input: Declare two variables length and width with values 20 and 10
Output: Area is 200

Problem 3: Fahrenheit to Celsius Conversion

Description: Write a Java program to convert a given temperature from Fahrenheit to Celsius.
Demonstrate the program by changing input values

Formula:

Example:

Input: Declare variable fahrenheit of double datatype and value 98.6
Output: Celsius = 37.0

Problem 4: Convert Minutes to Hours and Minutes

Description: Write a Java program to convert a given number of minutes into hours and remaining minutes. Demonstrate the program by changing input values

Example:

Input: Declare a variable duration (integer) with value 125
Output: Total Time = 2 hours and 5 minutes

Problem 5: Even or Odd Checker

Description: Write a Java program to check if a given number is even or odd using terinary operator
Demonstrate the program with different values

Example:

Input: Declare a integer variable with value 29
Output: 29 is odd number

Problem 6: Character ASCII Value

Description: Write a Java program to find the ASCII value of a given character.
Demonstrate the program with different values

Example:

Input: Declare a variable of character datatype with value 'A'
Output: ASCII value of A is 65

Problem 7: Boolean Expressions

Description: Write a Java program to evaluate simple boolean expressions.
Demonstrate the program with different combinations

Example:

Input: Declare two variables a and b of boolean datatypes with values true and false
Output: AND: false, OR: true, NAND: true, NOR: false

Problem 8: Swapping Values

Description: Write a Java program to swap the values of two variables. Demonstrate the program by changing input values

Example:

Input: Declare two variables x and y of integer type and with values 15 and 5
Output: 
Before Swap: x = 5 and y = 15
After Swap: x = 15 and y = 5

Problem 9: Perimeter of a Circle

Description: Write a Java program to calculate the perimeter of a circle given its radius.
Demonstrate the program by changing input values

Example:

Input: Declare a variable radius with double datatype with value 7.0
Output: Perimeter: 43.98

Problem 10: Simple Interest Calculation

Description: Write a Java program to calculate simple interest.
Demonstrate the program by changing input values

Formula:

Example:

Input: principal = 1000, rate = 5, time = 2
Output: Simple Interest: 100.0

Problem 11: Check Positive or Negative Number

Description: Write a Java program to check whether input number is positive, negative, or zero.
Demonstrate the program by changing input values

Example:

InputOutput
-20Negative
0Zero
30Positive

Excercise 2 →


🔗 Related Topics: