Program to print the elements of an array present on odd position17 Mar 2025 | 1 min read In this program, we need to print the elements of the array which are present in odd positions. This can be accomplished by looping through the array and printing the elements of an array by incrementing i by 2 till the end of the array is reached. ![]() In the above array, the elements present on odd positions are a, c and e. Algorithm
Program:Output: Elements of given array present on odd position: 1 3 5 Next TopicJava Programs |
Program to print the elements of an array in reverse order In this program, we need to print the elements of the array in reverse order that is; the last element should be displayed first, followed by second last element and so on. Above array in reversed...
2 min read
Java program to print the following pattern on the console 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Algorithm: STEP 1: START STEP 2: SET n=5. STEP 3: SET i=0. REPEAT STEP 4 to STEP 8 UNTIL i<=n. STEP 4: SET j=0.REPEAT STEP 5 to STEP 6 UNTIL...
1 min read
In this program, we will create a doubly linked list and remove the duplicate, if present, by traversing through the list. Original List: List after removing duplicates: In above list, node2 is repeated thrice, and node 3 is repeated twice. Current will point to head, and index will...
7 min read
Java String to long We can convert String to long in java using Long.parseLong() method. Scenario It is generally used if we have to perform mathematical operations on the string that contains long number. Whenever we get data from textfield or textarea, entered data is received as a string....
1 min read
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to discuss...
5 min read
Java Convert Date to Timestamp We can convert Date to Timestamp in java using constructor of java.sql.Timestamp class. The constructor of Timestamp class receives long value as an argument. So you need to convert date into long value using getTime() method of java.util.Date class. You can also format the...
2 min read
In this program, we need to find the most repeated word present in given text file. This can be done by opening a file in read mode using file pointer. Read the file line by line. Split a line at a time and store in...
4 min read
Java Convert Decimal to Hexadecimal We can convert decimal to hexadecimal in java using Integer.toHexString() method or custom logic. Java Decimal to Hex conversion: Integer.toHexString() The Integer.toHexString() method converts decimal to hexadecimal. The signature of toHexString() method is given below: public static String toHexString(int decimal) Let's see the simple example of...
1 min read
Java Convert Decimal to Binary We can convert decimal to binary in java using Integer.toBinaryString() method or custom logic. Java Decimal to Binary conversion: Integer.toBinaryString() The Integer.toBinaryString() method converts decimal to binary string. The signature of toBinaryString() method is given below: public static String toBinaryString(int decimal) Let's see the simple example...
1 min read
In this program, we need to find the transpose of the given matrix and print the resulting matrix. Transpose of Matrix Transpose of a matrix can be found by interchanging rows with the column that is, rows of the original matrix will become columns of the new...
4 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