Answer:
Follows are the code to the given question:
static int[] reOrder56(int[] nums)//defining a static method reOrder56 that holds an array in parameter
{
int x,y;//defining integer variables
for(x=0;x<nums.length;x++)//using for loop that counts array
{
if(nums[x]==5 && nums[x+1]!=6) //defining if block checks arry values
{
for(y=0;y<nums.length;y++)//use for loop to count array value again
{
if(nums[y]==6 && nums[y-1]!=5)//defining if block checks arry values
{
nums[y] = nums[x+1];//swap the array element value
nums[x+1] = 6;//holing value in array
break;//break the condition
}
}
}
}
}
Explanation:
In this code, a static method "reOrder56" is declared that takes an integer array "nums" in its parameter, and inside the method, two integer variable "x, y" is defined, which is used in the nested loop.
In the first loop, it holds array values and uses the if block to check the array element value and define another loop to check the same condition, and this block, swap the value and holds the value in the array and breaks the condition.