When I am printing contents of a string array the output is printing 'null' as well. I am not sure what's wrong with this. Here is the output, what I expect is the output without 'null'
null(wa?>=0)nullnull*(wo?>=0)nullnull*(4*wa?+7*wo?>=50)nullnull*(d1=10)nullnull*((d2=1)+(k=2))nullnull
Thanks and appreciate your help. I would say my skill in Java in beginner level and I started two weeks back.
Here is the actual code:
String[] arrStr = new String[50];
int countStr = 0;
for (int i = 0; i < para.length; i++) {
if (para[i] == '(') {
count = count + 1;
}
if (para[i] == ')') {
count = count - 1;
}
if (count > 0) {
arrStr[countStr] = arrStr[countStr] + para[i];
} else {
if (para[i] == ')') {
arrStr[countStr] = arrStr[countStr] + para[i];
countStr += 1;
} else {
countStr += 1;
arrStr[countStr] = arrStr[countStr] + para[i];
// System.out.println(para[i]);
}
}
}
System.out.println(countStr);
for (int i = 0; i < countStr; i++) {
System.out.print(arrStr[i]);
}
Before this part, I am reading the following string from a word document:
(wa?>=0)AND(wo?>=0)AND(4*wa?+7*wo?>=50)AND(d1=10)AND((d2=1)+(k=2))
I think the problem may be due to the line:
arrStr[countStr] = arrStr[countStr] + para[i];
Since arrStr[countStr]
is null initially and I add an element to it, it saves it as null+para[i]
. Do you think it is possible?
Like when I try: System.out.println(arrStr[0]);
I get the output as
null(wa?>=0)