# Thread: Get all values of variable that it can take

1. Member
Join Date
Jan 2009
Posts
3
Rep Power
0

## 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. 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. Member
Join Date
Jan 2009
Posts
3
Rep Power
0
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. 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. 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. ## 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

7. Senior Member
Join Date
Jan 2009
Posts
119
Rep Power
0
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. Member
Join Date
Jan 2009
Posts
3
Rep Power
0
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. ## 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

10. In every explanation he described different things I guess. May be he's looking some code from us, without putting any effort.

#### Posting Permissions

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