Print Left Triangle Star Pattern in Java

Manisha Chand
Updated on 18-Jun-2025 18:10:29

994 Views

In this article, we will understand how to print the left triangle star pattern in Java. This pattern is also known as the Mirrored Right Triangle Star pattern. Below is a demonstration of the same- Input: Number of rows: 6 Output: * * * * * * * * * * * * * * * * * * * * * Printing Left Triangle Star Pattern Following are the ... Read More

Find Sum of N Numbers Using Recursion in Java

Manisha Chand
Updated on 18-Jun-2025 18:07:15

577 Views

In this article, we will learn how to find the sum of N numbers using recursion in Java. Recursion is when a method calls itself repeatedly until a base condition is met. In Java, each recursive call is placed on the stack until the base case is reached, after which values are returned to calculate the result. To solve with recursion, we need to divide our problem into smaller chunks, then find out solution for that smaller part, and that will be our base condition. In this problem, to find the sum of N numbers using recursion, we can store ... Read More

Find Product of Two Numbers Using Recursion in Java

Manisha Chand
Updated on 18-Jun-2025 17:58:19

709 Views

In this article, we will understand how to find the product of two numbers using recursion in Java. A recursive function is a function that calls itself multiple times until a particular condition is satisfied. Product of two Numbers Using Recursion Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. To find the product of two numbers, let's say a and b, using recursion, the base case will be (if y = 0, ... Read More

Find Sum of Digits of a Number Using Recursion in Java

Manisha Chand
Updated on 18-Jun-2025 17:52:44

1K+ Views

In this article, we will understand how to find the sum of the digits of a number using recursion in Java. A recursive function is a function that calls itself multiple times until a particular condition or base condition is met. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. Problem Statement Write a program in Java to find the sum of the digits of a number using recursion. Below is a demonstration of the same. Input Enter the number : 12131415 ... Read More

Calculate Power Using Recursion in Java

Manisha Chand
Updated on 18-Jun-2025 17:50:23

1K+ Views

To calculate the power of a number, Java provides different ways to do this using loops, built-in methods, and recursion. In this article, we will learn how to calculate the power of a number using recursion. In Java, Recursion is a process in which a function calls itself multiple times until it reaches a base condition, and the corresponding function is called a recursive function. Problem Statement Given a base number and a power value, we need to calculate the result of raising the base to the power using recursion. Below is a demonstration of the same. Input: Enter ... Read More

Find Factorial of a Number Using Recursion in Java

Manisha Chand
Updated on 18-Jun-2025 17:05:44

903 Views

In this article, we will understand how to find the factorial of a number using recursion in Java. The factorial of a positive number is the product of the number itself and all descending positive integers up to "n". The factorial of a negative number does not exist, and the factorial of 0 is 1. The factorial of a positive number is - factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n Factorial Using a Recursive Function A recursive function is a function that calls itself multiple times until a particular condition is satisfied. ... Read More

Get Input from the User in Java

Manisha Chand
Updated on 18-Jun-2025 17:03:39

2K+ Views

In this article, we will understand how to get input from the user in Java. Java provides a built-in Scanner Class that belongs to the java.util package. The Scanner class is used to get user input. In this article, we will learn how to take different types of input, like integers, floating numbers, strings, etc., from the user in Java. Algorithm Following are the steps to get input from the user - Step 1- START Step-2- Import the Scanner class Step 3- Create a Scanner object Step 4- Prompt the user to enter ... Read More

Get Key from HashMap Using the Value in Java

Aishwarya Naglot
Updated on 18-Jun-2025 16:36:37

6K+ Views

Java HashMap is a hash table-based implementation of Java's Map interface. It is a collection of key-value pairs. In this article, we will understand how to get a key from a HashMap using the value. Following are the ways to get a key from a HashMap using the value: Using For Loop Using Stream API Using For Loop We can iterate through the entries of the HashMap using a for loop and check if the value matches the one we are looking for. If it does, we return the corresponding ... Read More

Check if a Set is the Subset of Another Set in Java

Aishwarya Naglot
Updated on 18-Jun-2025 16:27:32

1K+ Views

In this article, we will understand how to check if a Set is a subset of another set. A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are not allowed. Following are the ways to check if a set is a subset of another set: Using containsAll() Method Using Stream API Using containsAll() Method In Java, the set interface has a method called containsAll() that checks ... Read More

Pass ArrayList as Function Argument in Java

Aishwarya Naglot
Updated on 18-Jun-2025 16:25:40

4K+ Views

The ArrayList is a resizable array, which is part of java.util package. The difference between a built-in array and an ArrayList in Java is that the size of an array cannot be modified. In this article, we will understand how to pass an ArrayList as a function argument. Following are the ways to pass an ArrayList as a function argument: Using Function Argument Using Return Type Using Function Argument We can pass an ArrayList as a function argument in Java. The function can take an ArrayList as a parameter and perform operations ... Read More

Advertisements