Click to See Complete Forum and Search --> : Counting


blaze12364
March 24th, 2008, 09:36 PM
Below is a piece of my program, i have printed out all the expressions. As the number of expressions it prints is incredibly large (over 5,000) and takes time i want to be able to count the number of expressions it will print instead of actually printing all the expressions.

Can anyone help?


newCalcWaiting=true; // to deal with a later possible equality
i = iva_level(level);
for (j = iva_level(level+1) ; j < iva_level(level+2) ; j++)
{if (i == highV[level])
{// ignore the first of the contributors to calculation
i++;
}
if (i == lowV[level])
{// ignore the second of the contributors to calculation
i++;
}
if (newCalcWaiting && (sorted[i]<=thiscalc
|| iva_level(level+1)<=i ) )
{// insert the new calculation into the next level
sorted[j]=thiscalc;
expression[j]=newform;
newCalcWaiting=false;
System.out.println("expression = " + expression[j]);
System.out.print(sorted[j]);
System.out.println();

}

masher
March 24th, 2008, 10:47 PM
Instead of this:


System.out.println("expression = " + expression[j]);
System.out.print(sorted[j]);
System.out.println();


just make up a variable (maybe int expressionCounter) that you increment each time. Then at the end of the for loop, you can use that number as a counter for how many expressions you've done.