Trying to have my method parse multiple words in a sentence but it only parses the first word.
up vote
-2
down vote
favorite
It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.
public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}
java arrays split
|
show 8 more comments
up vote
-2
down vote
favorite
It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.
public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}
java arrays split
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
2
How do you know that only the first word is used? I hope not viaSystem.out.println(words[1]);because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g.pointsisn't defined and neitherbadListnor the result ofparseWordis being used.
– Thomas
Nov 19 at 15:59
How might I do that?
– Jake The Steak
Nov 19 at 16:01
1
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
1
BTW, ifwords.lengthequals 1, you should get an Exception when printingwords[1]
– Robert Kock
Nov 19 at 16:12
|
show 8 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.
public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}
java arrays split
It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.
public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}
java arrays split
java arrays split
asked Nov 19 at 15:57
Jake The Steak
61
61
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
2
How do you know that only the first word is used? I hope not viaSystem.out.println(words[1]);because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g.pointsisn't defined and neitherbadListnor the result ofparseWordis being used.
– Thomas
Nov 19 at 15:59
How might I do that?
– Jake The Steak
Nov 19 at 16:01
1
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
1
BTW, ifwords.lengthequals 1, you should get an Exception when printingwords[1]
– Robert Kock
Nov 19 at 16:12
|
show 8 more comments
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
2
How do you know that only the first word is used? I hope not viaSystem.out.println(words[1]);because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g.pointsisn't defined and neitherbadListnor the result ofparseWordis being used.
– Thomas
Nov 19 at 15:59
How might I do that?
– Jake The Steak
Nov 19 at 16:01
1
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
1
BTW, ifwords.lengthequals 1, you should get an Exception when printingwords[1]
– Robert Kock
Nov 19 at 16:12
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
2
2
How do you know that only the first word is used? I hope not via
System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.– Thomas
Nov 19 at 15:59
How do you know that only the first word is used? I hope not via
System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.– Thomas
Nov 19 at 15:59
How might I do that?
– Jake The Steak
Nov 19 at 16:01
How might I do that?
– Jake The Steak
Nov 19 at 16:01
1
1
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
1
1
BTW, if
words.length equals 1, you should get an Exception when printing words[1]– Robert Kock
Nov 19 at 16:12
BTW, if
words.length equals 1, you should get an Exception when printing words[1]– Robert Kock
Nov 19 at 16:12
|
show 8 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378380%2ftrying-to-have-my-method-parse-multiple-words-in-a-sentence-but-it-only-parses-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58
2
How do you know that only the first word is used? I hope not via
System.out.println(words[1]);because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g.pointsisn't defined and neitherbadListnor the result ofparseWordis being used.– Thomas
Nov 19 at 15:59
How might I do that?
– Jake The Steak
Nov 19 at 16:01
1
This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10
1
BTW, if
words.lengthequals 1, you should get an Exception when printingwords[1]– Robert Kock
Nov 19 at 16:12