I tried some ways to detect EOF in my code, but it still does not work. I tried using BufferedReader, Scanner and using char u001a to denote EOF, but still makes no sense to my code. Here is my last code:
Scanner n=new Scanner(System.in);
String input;
int counter=0;
while(n.hasNextLine())
{
input=n.nextLine();
char[] charInput=input.toCharArray();
for (int i = 0; i < input.length(); i++) {
if(charInput[i]=='"')
{
if(counter%2==0)
{
System.out.print("``");
}
else
{
System.out.print("''");
}
counter++;
}
else
{
System.out.print(charInput[i]);
}
}
System.out.print("\n");
}
The program should stop when it already reaches EOF, but I don’t know why, for some reason, it continues to work and leads to a runtime error. Please help. By the way, I'm new here, I'm sorry if my question is not entirely clear so that they understand it, Thank you earlier :)
source
share