Question: Java: Need code: - a negative number should have a minus sign followed immediately by a digit or a decimal point; further, negative numbers should

Java: Need code:

- a negative number should have a minus sign followed immediately by a

digit or a decimal point; further, negative numbers should usually

be surrounded by parentheses.

OK: 5 + (-13) or 5 -( -13) or 3+ (-.123) etc.

If you want to permit -7 + 16, the code will need to be

more complicated, so tell the "user" what is permitted.

Not OK: 5 + -13 or 5 - -13 or 5 + (- 13) or - .7 + 16 etc.

Indicating a negative number with (-x) is more natural than using _x,

but it causes difficulties because we also use parentheses

to enclose subexpressions, e.g. 3*(4+5). Without parentheses,

this would compute (left to right) as17 instead of 27. But the

dual role of parentheses requires extra attention.

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!