Create a random array of numbers from 1 – 10. Then, move all of the 7s to the front of the array. The order of the other numbers is not important as long as all numbers follow the group of Lucky 7s. Looking at the code for insertion sort and selection sort might be very helpful for this assignment. Arrays.toString() will also be useful. For instance, if you are given the list :: 4 5 6 7 1 2 3 7 The list could become – all 7s must be first :: 7 7 6 4 1 2 3 5
My code:
public class NumberShifter
{
public int[] go(int[] arrayToBeShifted, int index)
{
int originalArray[] = new int[index];
int valueBeingMoved = originalArray[index];
for (int i = index; i > 0; i--)
{
arrayToBeShifted[i] = arrayToBeShifted[i-1];
}
arrayToBeShifted[0] = valueBeingMoved;
return arrayToBeShifted;
}
}
The runner:
class Main
{
public static void main(String[] args)
{
int random[] = new int[10];
for(int i=0; i<random.length; i++)
{
random[i] = (int)(Math.random()*6)+1;
}
NumberShifter rt = new NumberShifter();
System.out.println(rt.go(random,7));
System.out.println(rt.go(random,7));
System.out.println(rt.go(random,7));
System.out.println(rt.go(random,7));
}
}
This program give me the errors Please anyone tell me that i use a correct method to solve this question. If i use a wrong method for this question please solve this with correct method.