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
Printable View
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
What you exactly want to do in this way.Quote:
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
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
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?
do you mean somehting like this??
what kind of condition are you thinking of?Code:int x=5;
if(cond1) x=x + 2;
else if(cond2) x=x + 3;
else x=x+10;
if its simple add/sub, you can prob write some code like:
if args[0] == '+' do this ...
I think the OP wants something like this:
THe only way I can think to do it is execute each of the values and then go therough the conditionals.Quote:
The possible values that can be obtained are: 5,6,7 & 2398
Value obtained using user's condition is: 7
Make sense? Why it's needed that way, I don't knowCode: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.
Luck,
CJSL
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.
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?
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
In every explanation he described different things I guess. May be he's looking some code from us, without putting any effort.