Found 7442 Articles for Java

Java Program to Display Factors of a Number

Manisha Chand
Updated on 09-Jun-2025 12:39:33

7K+ Views

In this article, we will understand how to display the factors of a number. Factors are numbers that divide the original number without leaving a remainder. For example, 1, 2, 3, 4, 6, and 12 are factors of 12. If a and b are factors of a number, then a x b is also a factor of the number. If we multiply 3 and 5, we get 15. We say that 3 and 5 are factors of 15. The largest factor of any number is the number itself, and the smallest factor is 1. 1 ... Read More

Java program to display prime numbers between intervals using function

Alshifa Hasnain
Updated on 24-Dec-2024 17:46:58

574 Views

In this article, we will understand how to display prime numbers between intervals using a function in Java. We will be using two approaches: one with user input and the other with predefined input. Prime numbers The prime numbers are special numbers that have only two factors 1 and itself and cannot be divided by any other number. A number is a prime number if its only factors are 1 and itself. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is ... Read More

Java Program to Display Prime Numbers Between Two Intervals

Manisha Chand
Updated on 17-Jun-2025 19:21:10

2K+ Views

In this article, we will understand how to find prime numbers between two intervals. Prime numbers are special numbers that have only two factors, 1 and itself, and cannot be divided by any other number. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number. All other prime numbers are odd numbers. Problem Statement Write a program in Java to display all prime numbers between two given intervals. Below is a demonstration of the same. ... Read More

Java program to find the area of a parallelogram

AmitDiwan
Updated on 21-Oct-2024 11:06:11

593 Views

In this article, we will understand how to find the area of a parallelogram using Java. A 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 h Problem Statement Write a program in Java to find the area of a parallelogram. Below is a demonstration of the same − Input Base : 6 Height : 8 Output Area parallelogram is ... Read More

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

841 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

363 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

Advertisements