Java Program to right rotate the elements of an array17 Mar 2025 | 2 min read In this program, we need to rotate the elements of array towards its right by the specified number of times. An array is said to be right rotated if all elements of the array are moved to its right by one position. One approach is to loop through the array by shifting each element of the array to its next position. The last element of the array will become the first element of the rotated array. ![]() Consider the above array, if n is 1 then, all elements of the array will be moved to its right by one position that is the first element of the array will take the second position, the second element will be moved to the third position and so on. The last element of the array will become the first element of the array. Algorithm
Program:Output: Original Array: 1 2 3 4 5 Array after right rotation: 3 4 5 1 2 Next TopicJava Programs |
In this program, we need to calculate the difference between the sum of nodes present at odd levels and sum of nodes present at even levels. Suppose, if a tree contains 5 levels, then Difference = (L1 + L 3 + L5) - (L2 + L4) In...
8 min read
In this program, we will create a doubly linked list and delete a node from the end of the list. If the list is empty, print the message "List is empty". If the list is not empty, tail's ious node will become the new tail...
6 min read
It is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, Adobe, Apple, Infosys, 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,...
5 min read
Java Convert Binary to Decimal We can convert binary to decimal in java using Integer.parseInt() method or custom logic. Java Binary to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts string to int with given redix. The signature of parseInt() method is given below: public static int parseInt(String s,int redix) Let's see...
2 min read
A prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers cannot be divided by other than itself or 1. For example, 2, 3, 5, 7, 11, 13, 17... are the prime numbers. Note: 0 and...
6 min read
In this program, we need to create a singly linked list and display the list in reverse order. Original List Reversed List One of the approaches to solving this problem is to reach the end the of the list and display the nodes from tail to head recursively. Algorithm Create...
5 min read
Here, our task is to replace all the lower-case characters in the string to upper-case and upper-case characters to lower-case. For this purpose, we need to traverse the string and check for each character. If the character is a lower-case character, make it upper-case by using...
2 min read
Multiplication of matrix is a core concept in programming. We can perform matrix multiplication in Java using a simple nested for loop approach to advance approach. The nested for loop approach has a time complexity of O(n3). The time complexity of matrix multiplication can be improved...
17 min read
Java Convert Octal to Decimal We can convert octal to decimal in java using Integer.parseInt() method or custom logic. Java Octal to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts a string to an int with the given radix. If you pass 8 as a radix, it converts an octal...
2 min read
Krishnamurthy number is another special number in Java. A number is said to be Krishnamurthy if the factorial sum of all its digits is equal to that number. Krishnamurthy number is also referred to as a Strong number. Just like Prime and Armstrong numbers, Krishnamurthy number...
3 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