Java 我正在写一个程序,把名字输入到一个文本文件中
我想我正在写东西,所有的步骤都在写的地方,但我会出错,我会修复错误,然后出错更多。我做错了什么Java 我正在写一个程序,把名字输入到一个文本文件中,java,string,javac,do-while,Java,String,Javac,Do While,我想我正在写东西,所有的步骤都在写的地方,但我会出错,我会修复错误,然后出错更多。我做错了什么 //for part 1 write a program in java tht will take a series of names from the //user //and save them to a file. The user should be able to enter however many names //they want. //Be sure to include bas
//for part 1 write a program in java tht will take a series of names from the //user
//and save them to a file. The user should be able to enter however many names //they want.
//Be sure to include basic I/0 instructions so the user knows how to interact //with the
//command prompt.
import java.io.*;
import java.util.Scanner;
public class Series{
public static void main(string[] args){
Scanner reader = new Scanner(System.in);
String s;
do {
System.out.println("enter the name now, or enter DONE to close and save");
PrintWriter writer = new PrintWriter (new File("NewSeries.txt"));
s=reader.nextString();
writer.println(s);
} while (!s.equals("DONE"));
{
writer.close();
System.out.println("SAVED");
}
}
}
请具体说明——哪些错误?请格式化您的代码,以确保可读性。我已尝试修复您的代码格式,并已删除了非常分散注意力的注释。我注意到在do-while循环下有一个悬空块。为什么会在那个位置出现块?请注意,您希望在do while循环之前创建PrintWriter!