Write a java program to parse and evaluate programs consisting of assignment and
ID: 3548156 • Letter: W
Question
Write a java program to parse and evaluate programs consisting of assignment and print statements with fully parenthesized arithmetic expressions. For example, given the input
A = 5
B = 10
C = A + B
D = C * C
print(D)
your program should print the value 225. Assume that all variables and values are of type double. Use a symbol table to keep track of variable names.
Explanation / Answer
import java.util.Scanner;
class AddNumbers
{
public static void main(String args[])
{
double A,B,C,D;
A = 5;
B = 10;
C = A + B;
D = C * C;
System.out.println("A = "+A);//5
System.out.println("B = "+B);//10
System.out.println("C = "+C);//15
System.out.println("D = "+D);//225
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.