Here is the error message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown...
Type: Posts; User: Lotus2013
Here is the error message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown...
Again, Hello :)
I want to know how can I say that search the whole tokens[] Array and if you find the token containing "the" then print the next tokens till it was all finished.
int...
int lent = chars.size();
if(lent == 3){
int one = chars.get(2);
System.out.println(one);
}
}
I did this, but it doesn't work :|
The size of the arraylist is 3 and...
import java.util.ArrayList;
import java.util.StringTokenizer;
//import java.util.StringTokenizer;
public class Parser {
public static void main(String args[]){
...
Thank you :) :) And I also want to remove the plural s in the word. For example to make the word "tables" into "Table". :-?
There is also something else :-? for example when the parser finds the wanted word ( e.g it's the position (room) ) then I want to print it in this way:
Position: Room
I mean I want the first...
In some cases, there are more than just one word after the word "the" that declare the position. for example:
"There are 5 tables (dimension: 4 in 5 in 3 meters) in the Mike's room." Now I want to...
for(int i= 0; i < tokens.length; i++){
if(tokens[i].equals("the")){
System.out.println(tokens[i+1]);
}
I changed it and it worked :) Thank you :) :)
for(int i= 0; i < tokens.length; i++){
if(tokens[i] == "the"){
System.out.println(tokens[i+1]);
}
I did this but It doesn't work. It doesn't throw exception and doesn't have any...
for example: "There are 5 tables (dimension: 4 in 5 in 3 meters) in the room."
the position is this part: "in the room" and I want to say that:
if(tokens.equals("the")){...
I want to say that if the token equals to the, print the next token as position. How can I say this? :( Using split.
I changed the code in this way to use split method instead of StringTokenizer
public class Parser {
public static void main(String args[]){
parser("There are 5 table (dimension: 4 in...
StringTokenizer strTok = new StringTokenizer(str, " ");
It's the StrinTokenizer in which the tokens are separated by a space :-?
I think I got what you mean. I added this to the code and changed the verb to are, But it doesn't work :(
if(strTok.equals("are")){
System.out.println(strTok.nextToken());
}
Sorry, I made a mistake there. I wanted to say that if the verb was "are" print out the third token (which is the number) as number. I'm so sorry. And the reason why I am counting the tokens is...
I edited the code :)
import java.util.StringTokenizer;
public class Parser {
public static void main(String args[]){
parser("There is a table (dimension: 4 in 5 in 3 meters) in the room.");
}
I think I understood what you mean. I'll try to define the syntax and the rules for the parser. Thank you so much :) This is my first time to ask a question in a forum and I'm really happy about it....
Sorry I'm very new to the programming so I don't really get Norm's question :confused:
--- Update ---
Yes, all the tokens are delimited by space. The other thing is that the number may change,...
I guess I'd better use String tokenizer :-? I think It's much more efficient than split method. What is your opinion?
No, the position does not change. But the sentence itself may change. for example we may have: There are 67 whiteboards(dimension: 3 in 5 meters) in the class.
I used the substring method and split method but there are some points which I should pay attention to. One is that the verb here can change. for example if we have two or more tables, then the verb...
I'm not looking for ready made code. I just want some guidance on this. For example, which method can I use? What are the useful methods to write this code with?
Hello everybody :)
I've got a question. I want to know how can I write a parser
"There is a table(dimension: 3 in 4 in 5 meters) in the room"
in a way that the output would be this:
Type: table...