I recently wrote a program to convert a string from infix to post-fix in java!
To do that i used two strings 's'
and 'p'
.
I initialized both strings with 'NULL'
.
Then i got the value of s from user using Scanner class.
s=s1.nextLine();
so if user enter "a+b"
, then s has the value "a+b"
. Note that 'NULL'
is no longer the part of the string!
Now I manipulate p using the concatenation operator '+' like:
p = p + '*';
I do get my post-fix string: i.e.
ab+.
Problem is that this time, NULL does not disappear! The value of p is:
"nullab+"
instead of "ab+"
.
Now I know my concatenation operator is causing problems! It adds to the string!
But java [eclipse indigo] does not let me use an operator without initializing it first! What do I do? Please help!
Thank you
Anuj Kalra