dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to do a trace table?

  1. #1
    Join Date
    Dec 2005
    Posts
    1

    How to do a trace table?

    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?

    so let's say..
    pin= 22
    product= 1
    digit=1
    digit != 0 = 22
    sum= 22
    sum%10= 2
    product%10=22
    final boolean= false

    and so.. what else now? =[

    I also have an encrytion program... but I want to see if I can understand this first. Thanks =]
    Last edited by LearningNerd; 12-07-2005 at 05:35 PM. Reason: stupid math makes me think truth table

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,140
    ummm..didnt understand ur quetion..can u elaborate pls
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Oct 2004
    Location
    The very depths of programming hell
    Posts
    828
    Umm... what do you mean by a "trace table"?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles