即使文件explicit.txt 只有单词abazure 程序没有进入if 语句,我也遇到了if 语句的问题。程序只是通过 if 语句并再次输出单词 abazure。
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class Manzai {
public static void main(String[] args) {
String word;
Scanner input = null;
PrintWriter output = null;
try
{
input = new Scanner(new File("explicit.txt"));
output = new PrintWriter(new File("censored.txt"));
}
catch(FileNotFoundException e)
{
System.out.println("File explicit.txt was not found");
System.exit(0);
}
while(input.hasNext())
{
word = input.next();
if(word=="abazure")
{
word = "a******";
}
output.print(word + " ");
}
input.close();
output.close();
}
}