I am currently working on an assignment and my task is to read an input of a couple of sentences on multiple lines and print out the words in two columns in an output file. I have completed the assignment for the most part however the program is writing the second word of some lines in another column. Does anybody know what is going on?
Here is the text of the input file:
This summer I will be going to training. I will be going to training for PLTW CSP. It will be two weeks long. It should be in san jose.
I love pizza! I also like to eat burgers. I want to die. The square root of 81 is 9.
I want to play checkers. I also would like to play chess.
Heaven would be something I aspire to go to.
The square root of 64 is 8.
I cannot wait to eat my pizza.
Samsung just released a new phone
I have an LG G7.
Atom is my editor of choice.
I need to get a new tv.
*Note: The first line ends at "in san jose."
Here is the code:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File inputFile = new File("input.txt");
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter("output.txt");
//in.useDelimiter("[^A-Za-z]+");
String input = "";
while (in.hasNextLine()) {
int count = 0;
input = in.nextLine();
input = input.replace(".", "");
input = input.replace("!", "");
Scanner lineScanner = new Scanner(input);
String words = "";
while (lineScanner.hasNext()) {
count++;
words = lineScanner.next();
out.printf("%10.10s", words);
if (count % 2 == 0) {
out.println();
}
}
}
out.close();
}
}
This is the output:
This summer
I will
be going
to training
I will
be going
to training
for PLTW
CSP It
will be
two weeks
long It
should be
in san
jose I love
pizza I
also like
to eat
burgers I
want to
die The
square root
of 81
is 9
I want
to play
checkers I
also would
like to
play chess
Heaven would
be something
I aspire
to go
to The square
root of
64 is
8 I cannot
wait to
eat my
pizza Samsung just
released a
new phone
I have
an LG
G7 Atom is
my editor
of choice
I need
to get
a new
tv