So let's say I have an array called arr with the values &&&&.&&. I want to find the number of ampersands (&) that are after the decimal point and store the value into numDecimalDigits.
int numDecimalDigits = 0;
char[] arr = new char[7]
for (int i = 0; i < str.length(); i ++)
{
for (int decimal = (arr[pos] = '.'); decimal <= arr.length; decimal ++)
{
numDecimalDigits += 1;
}
}
I'm not sure if this is the right approach. So the outside for loop runs through each index value of the array. The inner for loop starts at the decimal, and ends at the end of the array. Every time a new value is found, numDecimalDigits is added by one. However, in my code I think numDecimalDigits is returning an incorrect value.
(arr[pos] = '.')? What it does is set arr[pos] to '.' (whatever pos is).forloop at where the decimal point began, and end the loop at the end of the array.posis just short for "position" (i.e. position in array)==.=is assignment.)(arr[pos] = '.')doesn't tell you where the decimal point is, it assigns '.' toarr[pos].