파일의 내용을 읽고 각 줄을 역순으로 인쇄해야하는 Java 프로그램에서 작업하고 있습니다. 예를 들어 텍스트 :ArrayList Java의 역방향 코드
Public Class Helloprinter
Public static void
내 역 프로그램을 실행 한 후 다음을 인쇄 할 것이다 : 여기
retnirPolleh ssalc cilbup
diov citats cilbup
는 내가 지금까지 가지고있는 작업은 다음과 같습니다
public static void main(String[] args) throws FileNotFoundException {
// Prompt for the input and output file names
ArrayList<String> list = new ArrayList<String>();
//String reverse = "";
Scanner console = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = console.next();
System.out.print("Output file: ");
String outputFileName = console.next();
// Construct the Scanner and PrintWriter objects for reading and writing
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(outputFileName);
String aString = "";
while(in.hasNextLine())
{
String line = in.nextLine();
list.add(line);
}
in.close();
for(int i = 0; i <list.size(); i++)
{
aString = list.get(i);
aString = new StringBuffer(aString).reverse().toString();
out.printf("%s", " " + aString);
}
out.close();
}
} 편집 :
로버트의 글을 게시하면 나를 올바른 방향으로 인도 할 수있었습니다. 문제는 그것이 라인을 유지하지 않는다는 것입니다.
Public Class Helloprinter
Public static void
내 프로그램을 실행 한 후이된다 :
retnirPolleh ssalc cilbup diov citats cilbup
는 동일한 라인 레이아웃을 유지해야합니다. 따라서 다음과 같아야합니다 :
retnirPolleh ssalc cilbup
diov citats cilbup
당신이지고 어떤 출력? –
당신은 아마 우리에게 일하지 않는 것을 말해야 할 것입니다. – luuksen
무엇이 당신의 질문입니까? – fishinear