Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Assignment #32  
CSC 260 
 
A valid Java expression has to have parentheses and square brackets properly matched. 
(2*(a[i]+3)) is a valid expression. 
(3*(x+2) is invalid since it missing the closing parenthesis. 
Your program should ask the user to enter a Java expression.  Then, it should tell the user whether the 
expression is valid or invalid. 
We will process each character in the expression.  Push opening parentheses ‘(‘ and opening square 
brackets ‘[‘ on a stack. 
When your program comes to a closing parenthesis ‘)’ or square bracket ‘]’, the corresponding opening 
parentheses ‘(‘ or opening square brackets ‘[‘ should be at the top stack.  If it is not, the expression is 
invalid.  Otherwise, the opening ‘(‘ or ‘[‘ should be popped off the stack. 
All other characters in an expression should be ignored. 
When you reach the end of the expression String, the stack should be empty.  If it is not, the expression 
is invalid. 
There is a link to Stack.java on the class website. Use this Java class for this assignment.   
Test cases: 
Valid expressions:  
(2*(a[i]+3)) 
(x+1)*(x+2) 
Invalid expressions: 
 (3*(x+2) 
 (3*(x+2))) 
 (x[(i]))