please urgent help needed.
through this program i want extract the variable name + value and store to array-list and also find if-else and execute its body but it does not work
Output of program...
expected out put b=0.4;
System.out.println("please enter the number"45);
System.out.println("sum is grater than 100"45);
System.out.println("i is grater than 50"45);
System.out.println("sum is less than 50"45);
it's really hard to follow the flow of your code, since you crammed it all into the main method. This is not good programming practice.
Can you explain how you are trying to find all the variables, and their values? You should be able to do this in English (or whatever natural language you prefer) before you write one line of Java.
I would suggest you comment out everything after your // variables loop. then, in that loop, put a ton of System.out.println statements to see what it is doing. Get THAT piece to work first. Make sure you are simply finding the right strings from your sourcefile before you try and save them + their values values...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
You will never get that output, for a few simple reasons:
1) You loop over the types first. As a result, you will never get b=0.4 before sum=45[/url], because [tt]sum is an int and b is a float, and you always process ints before floats. You probably want to go over the tokens first.
2) You only process assignments that occur with declarations. The variables your code finds are int sum=null (because it doesn't come with a direct assignment), int n = 10, int count = 0, int i = 0, float b = 0.4 and String name = "David". All other assignments get lost.
3) I think you want your code to run this program, but it doesn't evaluate boolean expressions, perform any of the assignments other than those of reason 2, and doesn't perform any loops.
If I am correct in my assumption on what you want to do (run programs), drop everything you've done. Parsing a complex language is even more complex, and then running it all is even more complex. Instead, use what Java already provides (note: you need to run your program using a JDK, a JRE is not enough). First, use JavaCompiler to compile your source file, then use reflection (in combination with URLClassLoader) to load your new class and execute it.
please do not think about logic of that sample code i am going to read only i want to store the name of variable+ its value and also i find if-else and print their body please give me a code i am new in java and it is urgent