ppllmmnn 0 Newbie Poster
import java.io.*; import java.util.*;


public class UMUC { 
public static void main(String[] args) throws Exception { 

String s1 = "input.txt"; 

String s2 = "output.txt"; 


		try {

 


		FileReader fr = new FileReader(s1);

		BufferedReader br = new BufferedReader(fr);

		String lineRead = br.readLine();

		while(lineRead != null){

		s2 = s2 + "\n" + lineRead;

		lineRead = br.readLine();

				}

 

		br.close();

 

		} catch (FileNotFoundException e) {

		e.printStackTrace(); // Display the error

		System.exit(1); // Stop the program from running

		} catch (IOException e) {

		e.printStackTrace();

		System.exit(1);

		} 

//If there's a line, read it 

String[] wordList = s2.split("\\s"); 

int counter = 0; 
for (int i = 0; i < s2.length(); i++) { 

if (s2.charAt(i) == '4') counter++; } 

	
	String outputFilename = "output.txt";
		try {

		FileWriter fw = new FileWriter(outputFilename);

		BufferedWriter bw = new BufferedWriter(fw);

bw.write("The length of the string is: " + s2.length()); 
bw.write("The number 4 is entered in the text " + counter + "times."); 

String reverse = new StringBuffer(s2).reverse().toString(); 

bw.write("Reverse: " + reverse); 
String change = s2.replaceAll("this", "that"); 

bw.write(change); 


	bw.close(); // Always remember to close the file

		} catch (IOException e) {

		e.printStackTrace();

		System.exit(1);


		}}
		}

my output.txt is ending up looking like this:

The length of the string is: 19The number 4 is entered in the text 1times.Reverse: taC4sihT
txt.tuptuooutput.txt
This4Cat

how do i make each answer go to its' own line?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.