Large string input isn't being read completely, on an online judge [closed] - java

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 4 days ago.
Improve this question
There's a question on Codechef. A test case in this, where a string of length 100000, is being input. But when i print the length of string after input, its only coming out to be 65526. Why is that so? Is the input not being taken properly?
For input I use,
JAVA CODE:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 131072);
int n = Integer.parseInt(br.readLine());
String c = br.readLine();
NOTE : I also tried doing it in C++, but same problem occurs there.
I also tried, increasing the buffer size in case it causes problem, but no effect.
Also, Scanner didn't work in java!
Can someone please tell me what's going wrong?

Related

Read a csv file into one String [closed]

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 9 months ago.
Improve this question
I want to essentially read the contents of csv file and want to input into one string to return. I tried this and it doesnt quite work:
File file = new File(aaa.csv);
FileWriter fw = new FileWriter(file);
BufferReader bw = new BufferReader(fw);
String s;
while (bw.readLine() != null) {
s += (bw.readLine());
}
fw.close();
Is there a easier solution to reading csv file into string that works?
To read the entire file, assuming Java 11 and above, you can simply do:
String content = Files.readString(Paths.get("aaa.csv"));
note that if the file is very large memory becomes a problem.

why does the loop on this program time out? [closed]

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 4 years ago.
Improve this question
it works fine for some strings, but for some reason it does not work for the last three. I see no difference to the type of strings being entered and I expect indx to evaluate to -1, but for some reason it does not on the last three strings. I don't understand why.
edit: problem solved. As you guys said, I was taking the substring of str instead of news within the loop. Sorry for such a simple mistake guys, I'm just starting to code and these are the details I need to pay attention to more. Also as I am working within the codingbat website there is no debugger, but I also want to highly recommend that website for other beginners. It will give you many example problems to begin coding on. Thanks again.
enter image description here
code:
public String stringYak(String str) {
int indx = str.indexOf("yak");
String news =str;
for(;indx!=-1;)
{
news = (str.substring(0,indx) + str.substring(indx+3,str.length()));
indx = news.indexOf("yak");
}
return news;
}
Because loop never breaks.
You are taking substring from str index from news inside the loop.
May be you want to take both substring and index from news.

Can 'split' be used? [closed]

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 5 years ago.
Improve this question
I get this error "cannot resolve symbol method ‘split’ (java lang string)", when I try using the code below.
What could be causing the "split" error?
What is required to use "split" do I need to import android?
public void run() {
byte[] buffer = new byte[2048];
int mybytes;
String fields[];
while (true) {
try {
mybytes = mmInStream.read(buffer);
String readMessage = new String(buffer, 0, mybytes);
System.out.print("|mybytes|:\t" + mybytes);
fields = mybytes.split(" ");
heat = Integer.parseInt(fields[1]);
speed = Integer.parseInt(fields[3]);
You need to Declare Your mybytes as String not as a int change it
Use this
String mybytes;
Instead of this
int mybytes;
Okay, first off I'll address your question:
You're trying to perform a split on an int, not a stream, change the line
fields = mybytes.split(" ");
to
fields = readMessage.split(" ");
Regarding the structure of the questions itself:
Next time you're going to ask a question refer to How to ask.
Please provide the log-cat (or just stack-trace) for the error.
Please explain what you tried to do.
Please provide the entire code related to your problem, and not just a couple of lines with a bunch of blank lines inside of them.
Again, next time please refer to the How to ask because if you post a question in the same format, you might very well be blocked from asking questions again.
I think you intend to split buffer, not mbytes
You are trying to split an int. Instead, use a String, like :
String mybytes;
mybytes = String.valueOf(mmInStream.read(buffer));
fields = mybytes.split(" ");
Or you can use
fields = readMessage.split(" ");

BufferedReader gives null when file is not in Documents [closed]

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 5 years ago.
Improve this question
I am working on a text editor software(kinda like notepad) and whenever I open files from Documents, correct data is displayed but at any other location Null is returned
This is because bff.readLine() is returning null. According to the documentation, it returns null if the end of the stream has been reached.
The previous check bff.readLine() != null doesn't help, because each call advances the reader. Try it like that:
String line;
while ((line = bff.readLine()) != null) {
sk += line + "\n";
}

Remove single quotes in a string Java [closed]

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("'","");

Categories