I have code like this:
ans40 must be 2 but in some phones like Samsung s7 shows 3, how can I fix this?
sry for my poor English.
Thanks
I have code like this:
ans40 must be 2 but in some phones like Samsung s7 shows 3, how can I fix this?
sry for my poor English.
Thanks
You can just use the array returned by String#split
instead of using lots of variables.
String[] ans=anskey.split("");
Instead of using ans1
, you can then just use ans[0]
.
However, if you want to split for characters, you can also do it like this so you get a char[]
:
char[] ans=anskey.toCharArray();
This approach is way more robust as split
uses a regex.
And if you nedd to get the values of all variables, you can just iterate over them:
for(int i=0;i<ans.length;i++){
//Do something with ans[i]
}
or
for(String distinctAns:ans){
//Do something with ans[i]
}