So, I'm trying to repeat the int [] array with the values โโthat are in it. So basically, if you have an array of {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 result
{1,2,2,3,3,3}.
I know for sure that there should be two loops here, but I canโt understand the code so that it copies the value in the array. I can not get 2 to 2.2, Any help would be greatly appreciated, thanks.
edit the code here that 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 this would work, but it will just return the same list, or someday, if I change it around badly, just get 4 in a new array.
source share