Results 1 to 10 of 10
  1. #1
    umarsharief is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default Get all values of variable that it can take

    Dear All,

    I need to get all the values that a variable can take in the course of execution of the code:

    i.e:
    x=5;
    if(cond1)
    x=x + 2;
    if(cond2)
    x=x + 3;
    else
    x=x+10;

    output should be x can take : 7 , 8 , 15

    Thanks & Regards,
    Umar Sharief

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    x = 5;
    x = x + 2;
    // Get the first value and set back the value to 5

    x = 5;
    x = x + 3;
    // Get the next and do the same

    x = 5;
    x = x + 10;
    // Get the next
    What you exactly want to do in this way.

  3. #3
    umarsharief is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default

    condition is decided by the user as input:

    based on the users selection the program gives the output:

    prior to user selection i want to know what all values can x take if the program execution is done in all possible ways:

    that is i need to get an array of values that x can take if it cond1 is satisfied or something like that

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Just see your logic. You cannot access more than one condition at a time in the if-else statements. So how can you evaluate all possible values like this?

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    do you mean somehting like this??
    Java Code:
    int x=5;
    
    if(cond1) x=x + 2;
    else if(cond2) x=x + 3;
    else x=x+10;
    what kind of condition are you thinking of?
    if its simple add/sub, you can prob write some code like:

    if args[0] == '+' do this ...

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default hhhmmm...

    I think the OP wants something like this:
    The possible values that can be obtained are: 5,6,7 & 2398
    Value obtained using user's condition is: 7
    THe only way I can think to do it is execute each of the values and then go therough the conditionals.
    Java Code:
    x=5;
    x1=x + 2;
    x2=x + 3;
    x3=x+10;
    
    if(cond1)
    x=x + 2;
    if(cond2)
    x=x + 3;
    else
    x=x+10;
    
    print out x1, x2 & x3 and then print x.
    Make sense? Why it's needed that way, I don't know

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Can you confirm if I got your problem correctly?

    The problem is you want to generate all the possible value that the user keys in and have already prepared solutions (or number maybe) so that it prints out the result when the number is keyed in.

  8. #8
    umarsharief is offline Member
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Default

    What I exactly need to do is .....

    I need to get all the values that a variable can take and safe it into an array before running the program.

    and then check the probability of occurrence of each output when the program is run normally.

    the input to my program can be any java file and the output should contain the array of values a particular variable can take in different conditions?

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default OK... where's the code..

    Various people have tried to undertand your problem and have suggested a couple of ideas. So far, we haven't seen any code from you... what are you waiting for? Have you tried to code something?
    Show us what you have done.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 0
    Last Post: 05-22-2008, 10:53 AM
  2. Replies: 4
    Last Post: 04-15-2008, 01:04 PM
  3. getting the value of variable
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 03-05-2008, 01:42 AM
  4. Getting variable value from a variable name
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-16-2008, 09:26 PM
  5. How to get variable values at runtime in another process
    By murali_java in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2007, 08:03 AM

Posting Permissions

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