Android circular array generation issue -
i have tried write method generate array using base of operations pattern in way: method uses base of operations pattern , x
value, , must create result array of size x loading base
in circular way
if have
string base[] = "a", "b", "c"
if x=4
result should be
res[] = "a", "b", "c"
if x=11
"a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b"
and on
my code this
public static string[] circ(context c, int size){ string[] base of operations = {c.getresources().getstring(r.string.channela), c.getresources().getstring(r.string.channelb), c.getresources().getstring(r.string.channelc)}; string res[]; if(size>base.length){ int deltasize=size-base.length; int listsize=base.length+deltasize; res=new string[listsize]; for(int i=0; i<listsize; i++){ if(i<base.length){ res[i]=base[i]; } else{ res[i]=base[i-base.length]; } } } else{ res=base; } homecoming res; }
but doesn't work , cannot find wrong. suggestion?
you should utilize modulo operation, makes code easier:
public static string[] circ(context c, int size){ string[] base of operations = /.../ string res[]; (int = 0; < size; i++) { res[i] = base[i % base.length]; } homecoming res; }
android arrays
No comments:
Post a Comment