Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am trying to show my summary result in a textview is there any syntax to use other than return summary because I get an error of unidentified expression, and I dont know of any other syntax.
//construct the summary size out of select sentences
String summary = "";
summary = summary + "• " + firstSentence + System.getProperty("line.separator") + System.getProperty("line.separator");
for(String sentence : sentences)//foreach string sentence in sentences list
{
if(setSummarySentences.contains(sentence))
{
//produce each sentence with a bullet point and good amounts of spacing
summary = summary + "• " + sentence + System.getProperty("line.separator") + System.getProperty("line.separator");
}
}
return summary;
}
}
Your mistake is in the following line:
TextView textView3 = return summary;
You're trying to assign a return statement to a variable, which is not a valid syntax.
Please take a look at the Java tutorials, specially in the assignment and return sections.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
if(args.length != 1){
System.out.println("Incorrect number of arguments");
return;
}
String inString = "";
Scanner s = new Scanner(new FileReader(args[0]));
while(s.hasNextInt){
int temp = s.nextInt();
inString += temp;
}
This is an excerpt of code from my main method. Code won't compile; the two errors are cannot find symbol (s.hasNextInt) and illegal start of type (while(s)). The other question I found here about .hasNextInt and cannot find symbol was someone trying to call .hasNextInt on a string instead of a scanner, and I can't figure out why my scanner can't run hasNextInt. I imported .util and .io.
Can someone help me figure out what I'm doing wrong?
You're missing the brackets () for the method call hasNextInt().
while(s.hasNextInt()){
int temp = s.nextInt();
inString += temp;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
i have a simple function inside a class that checks if two strings are equal ( this is for a hangman game). The code is simple, with two class variables:
private String hiddenWord;
private String dashWord;
public void compareGuessWord(String clientGuess) {
if (clientGuess.length() > 1) {
System.out.println("Kollar om dashord: " + dashWord);
System.out.println("Kollar om hidden: " + this.hiddenWord);
System.out.println("Kollar om guess:" + clientGuess);
if (clientGuess.equalsIgnoreCase(this.hiddenWord));
{
this.dashWord = clientGuess;
}
System.out.println("SECOND Kollar om guess:" + clientGuess);
System.out.println("SECOND Kollar om dashord: " + dashWord);
System.out.println("SECOND Kollar om hidden: " + hiddenWord);
}
}
Here is the console output, which u can see that it is running the inner if even though they dont match.
problem
if (clientGuess.equalsIgnoreCase(this.hiddenWord)); Your if does nothing but checking. Remove the ; after it.
In your if condition have ';' so that if is not working
if (clientGuess.equalsIgnoreCase(this.hiddenWord))**;**
{
this.dashWord = clientGuess;
}
The compiler consider it as a normal statement, so remove semicolon ";" and check
your If Statement is getting terminated as you had put semicolon at the end
if (clientGuess.equalsIgnoreCase(this.hiddenWord));
remove the semicolon and it will work fine
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need some help to replace all the single quotes in a string.
This is my string: The State of the water = 'ICE'
I want to remove the single quotes around ICE.
str = str.replaceAll("\'","");
Use this
String str = "The State of the water = 'ICE'";
str = str.replaceAll("'","");
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
String x = "5+7";
String []n = x.split("\\+");
System.out.println(n[0]); // =5
System.out.println(n[1]); // =\
Your code should work fine, but I'd try to make it more robust:
String test = "5 + 7";
String[] tokens = test.split("\\s*\\+\\s*");
for (String token : tokens) {
System.out.println(token);
}
The \\s* will allow for possible white-space between the numbers and the + char.
use
x.split("[+]");
That will split it correctly.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I have some string.
String cos = "Something I do not know ThisIWantToFind Something I do not know";
And how I can find this with regex ?
I tried with:
result = cos.matches("(.*)ThisIWantToFind(.*)");
and
result = cos.matches("(.*?)ThisIWantToFind(.*?)");
but this not work :(
without regex
case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.indexOf("ThisIWantToFind") > -1)
{
// found
}
not case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.toUpperCase().indexOf("ThisIWantToFind".toUpperCase()) > -1)
{
// found
}
You want to know if the regex is in the string or the position of the regex in the string?
for the first one, I guess this should work ..
boolean result = cos.matches(".*ThisIWantToFind.*");
?