array rotation program in java
//Rotating array left
//d = number of rotations
static void rotLeft(int[] a, int d)
{
//using secondary array of same size
int [] n = new int[a.length];
//saving element into array n[] according to newlocation of rotations(d)
for(int i = 0; i < a.length; i++)
{
int newlocation = (i+(a.length - d))% a.length;
n[newlocation] = a[i];
}
//printing new rotated array
for(int i = 0; i < a.length; i++)
{
System.out.print(n[i]+ " ");
}
}
Also in Java:
- inheritance setter and getter in java
- adding an element to the end of a linked list java
- java string contains at beginning
- goodbye java
- java function for power
- string remove last character
- java doreturn void
- java how to print an array
- java import
- byte java
- usaco 2018 january contest
- nextchar in java
- java singleton implementation
- Filebody in java
- if else program in java
- web app runtime for java
- java djikstra's algorithm
- spigot sounds
- update value of an arraylist java
- java get annotation value
- set java
- java get folder content
- link to method javadoc
- java string to character stream