Found 9150 Articles for Object Oriented Programming

Java Program to Perform nCr (rcombinations)

Alshifa Hasnain
Updated on 27-Dec-2024 19:16:15

903 Views

In this article, we'll learn to perform nCr (Combinations) in Java. In mathematics, nCr (combinations) is a crucial concept that helps determine how many ways you can choose r items from a set of n items, without considering the selection order. It is widely used in fields like probability, statistics, and combinatorics.  What is nCr? The formula for calculating combinations (nCr) is − nCr = n! / (r! × (n - r)!) Where, n! = The factorial of n (product of all integers from 1 to n). r! = The factorial ... Read More

Java Program to Find the Perimeter of a Circle

Shriansh Kumar
Updated on 15-Aug-2024 13:05:46

1K+ Views

For a given circle with radius "r", write a Java program to find the perimeter of that circle. The circumference is also known as the perimeter. It's the distance around a circle. Circumference is given by the formula C = 2𝜋r where, pi/𝜋 = 3.14 and r is the radius of the circle − Example Scenario Input: radius = 5 Output: perimeter = 31.400000000000002 2 * 3.14 * 5 = 31.428571428571427 By Defining Constant Value for PI In this Java program, we define the value of PI as a constant and find the perimeter of circle ... Read More

Java program to find the area of a Trapezium

AmitDiwan
Updated on 29-Sep-2024 02:48:03

842 Views

In this article, we will understand how to find the area of a trapezium using Java. The trapezium is a type of quadrilateral that has at least one pair of sides 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 sides Below is a demonstration of ... Read More

Java Program to Reverse a Number

Shriansh Kumar
Updated on 18-Jun-2025 19:05:39

1K+ Views

For a given input number, write a Java program to reverse its digits. In reverse operation, we print the digits of given number from the last to start. The digit at the last position is swapped with the digit at the first position, the second last digit is swapped with second position digit and so on. Example Scenario: Input: number = 123456; Output: rev_number: 654321 How to Reverse a Number in Java? There are multiple ways to reverse the digits of a given number. We are going to discuss the following: Using ... Read More

Java Program to Print the Multiplication Table in Triangular Form

Manisha Chand
Updated on 09-Jun-2025 13:21:42

364 Views

In this article, we will understand how to print a multiplication table in triangular form. To print in triangular form, the table will display row and column-wise. And in every row, entries will be up to the same column number. Below is a demonstration of the same - Input : rows = 7 Output: 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 49 Multiplication Table in a Triangular Shape Multiplication table in triangular form is achieved using a nested ... Read More

Java program to check the birthday and print happy birthday message

Alshifa Hasnain
Updated on 06-Jun-2025 14:50:13

3K+ Views

In this article, we will understand how to check the birthday and print Happy Birthday message. Checking the birthday is achieved 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 Different ways to check the birthday ... Read More

Java Program to Check if two of three Boolean variables are true

Manisha Chand
Updated on 05-Jun-2025 10:51:50

472 Views

In this article, we will learn to check if any two out of three boolean values are true or not. Boolean variables are datatypes that contain only true or false values. Below is a demonstration of the same - Input: true, true, falseOutput : Two of the three variables are true Checking if two of three Boolean variables are trueIn this article, we will discuss two approaches to check it, and they are - Using if-else Condition ... Read More

Java Program to Implement Multiple Inheritance

Manisha Chand
Updated on 05-Jun-2025 11:10:33

15K+ Views

In this article, we will understand how to implement multiple inheritance. Unlike other programming languages, such as C++, Java does not support multiple inheritance through classes. This means that a class cannot inherit from more than one class. But why? Let's understand first what multiple inheritance is and why it is so. Multiple Inheritance Multiple Inheritance is one of the features of object-oriented programming, where a class (child class) can inherit properties of more than one class (parent class) using the extends keyword. But Java does not support this to avoid complexity and ambiguity. It can ... Read More

Java Program to Count the Number of Vowels and Consonants in a Sentence

Shriansh Kumar
Updated on 06-Jun-2025 14:00:42

2K+ Views

To count number of vowels and consonants in a given String, we can use the switch statement and if-else condition in Java. Alphabets that include 'a' 'e' 'i' 'o' 'u' are called Vowels and all other alphabets are called Consonants. Let's understand the problem statement with an example scenario. Example Scenario Suppose our input string is: Input: Hello, my name is Charlie Output: Vowels = 8, Consonants = 12 In the given string, the collective count of vowels is 8 and consonants is 12. Using switch Statement Run a for-loop, check each letter whether it is a consonant or ... Read More

Java Program to Compute Quotient and Remainder

Shriansh Kumar
Updated on 30-May-2025 17:05:52

1K+ Views

Given an integer a and a non-zero integer d, our task is to write a Java program to compute the quotient and remainder. Quotient can be calculated using the formula "Quotient = Dividend / Divisor" and for remainder, use "Remainder = Dividend % Divisor". When a number, i.e., dividend, is divided by another number, i.e., divisor, the quotient is the result of the division, while the remainder is what is left over if the dividend does not divide completely by the divisor. Example Scenario Suppose our input is - Input1: Dividend = 50 Input2: Divisor = 3 The output ... Read More

Advertisements