Question: (Java syntax checker) Write a program that checks whether a user-input Java for-loop definition is valid. Use the simplified rules that follow. No optional spaces

(Java syntax checker)

Write a program that checks whether a user-input Java for-loop definition is valid. Use the simplified rules that follow.

No optional spaces are allowed.

The statement is composed by 4 fields, delimited as follows

 substring1 ( substring2 ; substring3 ; substring4 ) 

substring1 must be the string "for".

substring2 must be the string "int" followed by a space, a string s (the variable name), the "=" sign, and an arbitrary string without spaces (i.e., it could be a number, a variable, etc.).

substring3 must be a string that starts with the string s used in substring2, followed by an inequality symbol and an arbitrary string without spaces (i.e., it could be a number, a variable, etc.).

substring4 must be a string that starts with the string s used in substring2, followed by "++" or "--".

These are simplified rules. Feel free to enrich them to accept any valid Java for-loop statement.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!