instead of
System.out.print("");
use
System.out.println("");
that will make your pointer go to a new line for each print
if you want to go and use excell files in java, you may want to look into JExcelapi or poi , a library by apache to use ms office files.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
Another way to have text be printed on more than one line is to insert a newline character ('\n') in the text at the point you want the following text to start on the next line. "Line 1\nLines 2\nLine 3" will print on 3 lines
The println() method automatically adds a newline character at the end of the String you are printing.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
I understand the \n and what the println() does.
To print this on one line put one lineend at the end of the String:
"Squad Rank Name SSN BloodType RifleType RifleSN AcogSN PeqSN\n"
If the String is in parts, use print() on all of the parts except the last one. Use println() on the last part to put the next thing printed on the next line.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
when you read it in from a file, as you plan to do it eventually, you'll be reading it line by line, not word by word, in which case both println and adding "\n" will do what you want it to do.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
Couple of ways:
Pad each string with spaces so Strings in a column have the same number of characters. By padding on the right for words and on the left for numbers you can have normal alignment for those types.
Insert tab \t characters between each column.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
The \n and \t characters are for the compiler when it reads your source. It converts them to the correct binary values. If you put them in a text file, the compiler is not involved in converting them to their binary values. When you read those two characters: "\n" (note this is a 2 char String) you will have to convert them to '\n' (note a 1 char value).
You would pad or use tabbing when you format the data for output to the screen.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
you don't need to have it in the file.
just have your application run a bit like:
-read a line from your file into StringLine
while ( StringLine != eof )
- print that line
- print "\n" (or use println, for that matter)
- read a line from your file
end while
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433