Program to print the elements of an array present on even position17 Mar 2025 | 1 min read In this program, we need to print the element which is present on even position. Even positioned element can be found by traversing the array and incrementing the value of i by 2. ![]() In the above array, elements on even position are b and d. Algorithm
Program:Output: Elements of given array present on even position: 2 4 Next TopicJava Programs |
A binary tree is given whose edges are undirected and whose nodes are connected. Also, the tree is not cyclic. The binary tree is made up of t nodes that are numbered from 0 to t - 1 and have exactly t - 1 edge. Every...
21 min read
In this program, we need to calculate the sum of elements in each row and each column of the given matrix. Above diagram shows the sum of elements of each row and each column of a matrix. Algorithm STEP 1: START STEP 2: DEFINE rows, cols, sumRow, sumCol STEP 3:...
3 min read
In this program, we will find out the smallest node in the given binary tree. We first define variable min that will hold root's data. Then, we traverse through left sub-tree to find the smallest node in left subtree. Compare it with min and store...
5 min read
How to reserve a string in Java without using reverse function There are following ways to reverse a string in Java: Using for loop Using While loop Using static method Using For loop Example to reverse string in Java by using for loop In the following example, we have used for loop to...
2 min read
In this program, we need to find out the maximum width of the binary tree. The width of the binary tree is the number of nodes present in any level. So, the level which has the maximum number of nodes will be the maximum width...
6 min read
In this program, we will create a circular linked list and remove duplicate nodes from the list. We will compare a node with rest of the list and check for the duplicate. If the duplicate is found, delete the duplicate node from the list. 1->2->2->4->3 In the...
2 min read
Problem Statement The problem states that a gardener wants to water a garden (single-dimensional) by opening the minimum number of taps. The task is to find the minimum number of taps that should be open to water the whole garden, return -1 if the garden cannot be...
17 min read
Write a code to prove that strings are immutable in java? Following program demonstrate it. File: ProveStringImmutable .java public class ProveStringImmutable { public static void referenceCheck(Object x, Object y) { if (x == y) { System.out.println("Both pointing to the same reference"); } else { System.out.println("Both are pointing to different reference"); } } public static void...
1 min read
Java Object class is the super class of all the Java classes. All Java classes implements the Object class by default. The Java Object class provides the two important methods to compare two objects in Java, i.e. equals() and hashCode() method. While Java provides built-in...
5 min read
Program to Print the Duplicate Elements of an Array | Find Duplicate Elements in an Array in Java Finding duplicate elements in an array is a commonplace programming hassle that assesses the know-how of statistics systems and algorithms. Understanding the different methods to find duplicates efficiently is...
9 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India