Found 9321 Articles for Object Oriented Programming

Java Program to Find the Area of a Parallelogram

AmitDiwan
Updated on 22-Feb-2022 07:40:07

362 Views

In this article, we will understand how to find the area of a parallelogramA parallelogram has two pairs of parallel equal opposite sides. It has a base and a height which is the perpendicular distance between the base and its opposite parallel side.The area of a parallelogram is calculated using the formula −base * height i.e. b x hBelow is a demonstration of the same −InputSuppose our input is −Base : 6 Height : 8OutputThe desired output would be −Area parallelogram is : 48 AlgorithmStep 1 - START Step 2 - Declare three integer values values namely Step 3 - ... Read More

Java Program to Perform nCr (rcombinations)

AmitDiwan
Updated on 22-Feb-2022 07:35:09

381 Views

In this article, we will understand how to compute the combination using n and r values. The nCr is calculated using the formula −(factorial of n) / (factorial of (n-r))Below is a demonstration of the same −InputSuppose our input is −Value of n : 6 Value of r : 4OutputThe desired output would be −The nCr value is : 15AlgorithmStep 1 - START Step 2 - Declare two integer values namely n and r. Step 3 - Read the required values from the user/ define the values Step 4 - Define two functions, one function to calculate the factorial of n and ... Read More

Java Program to Find the Surface area and Volume of Cuboid

AmitDiwan
Updated on 22-Feb-2022 07:28:57

402 Views

In this article, we will understand how to compute the surface area and volume the cuboid. Cuboid is a three-dimensional object with six faces of rectangle shape which means it has sides of different length and breadth. The difference between a cube and cuboid is that a cube has equal length, height and breadth whereas in cuboids these three are not sameThe surface area of cuboid is calculated using the formula −2*( length *width + width* height + height*length)The area of the cuboid is calculated using the formula −length*width*heightBelow is a demonstration of the same −InputSuppose our input is −Length= ... Read More

Java Program to Find the Perimeter of a Circle

AmitDiwan
Updated on 21-Feb-2022 13:18:08

828 Views

In this article, we will understand how to find the perimeter of a circle. The circumference is the perimeter of a circle. It's the distance around a circle.Circumference is given by the formula C = 2𝜋\pi r where, \pi𝜋 = 3.14 and r is the radius of the circle −Below is a demonstration of the same −InputSuppose our input is −Radius of the circle : 5OutputThe desired output would be −Perimeter of Circle is: 31.428571428571427 AlgorithmStep 1 - START Step 2 - Declare 2 double values namely my_radius and my_perimeter Step 3 - Read the required values from the user/ ... Read More

Java Program to Find the Area of a Trapezium

AmitDiwan
Updated on 21-Feb-2022 13:14:53

540 Views

In this article, we will understand how to find the area of a trapezium. Trapezium is a type of quadrilateral that has at least one pair of side parallel to each other. The parallel sides of a trapezium are called bases and the non-parallel sides of a trapezium are called legs. It is also called a trapezoid.The area of a trapezium is calculated using the formula −(height/2 * (side_1 + side_2). i.e. Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sidesBelow is a demonstration of the same. Area of a trapezium ... Read More

Java Program to Reverse a Number

AmitDiwan
Updated on 21-Feb-2022 13:04:36

460 Views

In this article, we will understand how to print an integer in Java. The reverse of a number is computed using a loop and arithmetic operator % and /.Below is a demonstration of the same −InputSuppose our input is −The number : 123456OutputThe desired output would be −The result is 654321 AlgorithmStep 1 - START Step 2 - Declare three integer values namely my_input, reverse_input and remainder. Step 3 - Read the required values from the user/ define the values Step 4 – Run a while loop Step 5- Use modulus of 10 and get remainder for ‘my_remainder’ . Step ... Read More

Java Program to Print the Multiplication Table in Triangular Form

AmitDiwan
Updated on 21-Feb-2022 12:52:45

259 Views

In this article, we will understand how to print multiplication table in triangular form. Printing multiplication table in triangular form is achieved using a loop.Below is a demonstration of the same −InputSuppose our input is −Input : 7OutputThe desired output would be −The result is : 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49AlgorithmStep 1 - START Step 2 - Declare 3 integer values namely my_input, I and j Step 3 - Read the required values from the user/ define ... Read More

Java Program to Generate Multiplication Table

AmitDiwan
Updated on 21-Feb-2022 12:43:21

806 Views

In this article, we will understand how to print a multiplication table. Multiplication table is created by iterating the required input 10 times using a for loop and multiplying the input value with numbers from 1 to 10 in each iteration.Below is a demonstration of the same −InputSuppose our input is −Input : 16OutputThe desired output would be −The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = 96 16 * 7 = 112 ... Read More

Java Program to Round a Number to n Decimal Places

AmitDiwan
Updated on 21-Feb-2022 12:39:49

251 Views

In this article, we will understand how to round a number to n decimal places. Rounding of decimal values are done using the CEIL or FLOOR functions.Below is a demonstration of the same −InputSuppose our input is −Input : 3.1415OutputThe desired output would be −Output : 3.2 AlgorithmStep 1 - START Step 2 - Declare a float variable values namely my_input. Step 3 - Read the required values from the user/ define the values Step 4 – Use the CEIL function to round the number to the required decimal places. In this example we are rounding up to 2 decimal ... Read More

Java program to check the birthday and print happy birthday message

AmitDiwan
Updated on 19-Jul-2024 14:23:10

2K+ Views

In this article, we will understand how to check the birthday and print Happy Birthday message. Checking the birthday is accomplished by comparing the present day and the given birthday. Problem Statement Write a program that checks if today's date matches a predefined birthday date. If the dates match, the program should print a "Happy Birthday" message otherwise, it should indicate that today is not the birthday. Below is a demonstration of the same − Input Birthday Date: 15 July Output Today’s Date is 20-12-2021 Today is not my birthday Check the Birthday Using LocalDate ClassBelow are the steps to check ... Read More

Advertisements