So I'm trying to repeat an int[] array by the values that are in it.
So basically if you have an array
{1,2,3,4}
your output will be
{1,2,2,3,3,3,4,4,4,4}
or if you get
{0,1,2,3}
your output is
{1,2,2,3,3,3}.
I know for sure there has to be two for loops in here but I can't seem to figure out the code to make it copy the value in the array. I can't get 2 to out 2,2, Any help will be much appreciated, thank you.
edit here the code I thought would work
public static int[] repeat(int []in){
int[] newarray = new int[100];
for(int i = 0; i<=in.length-1;i++){
for(int k= in[i]-1;k<=in[i];k++){
newarray[i] = in[i];
}
}
return newarray;
}
I thought that this would work but it just returns the same list, or sometime if I change it around ill just get 4 in the new array.