Well I'm new to Java programming and I have to make a trace table for a certain algorithm. I know it should be pretty simple, but here is the program I'm suppose to make it on.
public void tryValidPin()
{
int pin = 0;
do
{
pin = inputInt("Pin:");
output( validPin(pin) );
} while (!validPin(pin) && pin>0);
}
public boolean validPin(int pin)
{
int sum = 0;
int product = 1;
while (pin>0)
{
int digit = pin % 10;
sum = sum + digit;
if (digit != 0)
{
product = product * digit;
}
pin = pin / 10;
}
if ( (sum % 10) == (product % 10) )
{ return true; }
else
{ return false; }
}
Okay I know for the columns it is the varibles and boolean. So these are the varibles I found:
pin, product, digit, sum, digit !=0, sum, sum%10, product%10, the final boolean
Now my input is 22.. so how is this suppose to work really?
Bookmarks