SeidlerAM SeidlerAM - 1 year ago 55
Java Question

Java, tabs sometimes not generating in while loop

My code appears to work near flawless. This IS for a class assignment and I feel I have wrote everything correct, minus an error I can't find.

I am using Eclipse 4.6.1 and running Linux Mint 18 (KDE)

I have ran the application through Terminal and I get the same error.
Also, the error is printed to the file just like what I see in the terminal and Eclipse console.

The userNames.txt file must contain an individual name per line. The output places a header, then a username, TAB, and then a password, NEW LINE, username, TAB, and password.

The problem is I am not always getting tabs between the username and password. What did I do incorrectly, please?

EDIT: I switched the println to printf with %10s and fixed the issue.

username =;
password = getPassword(ch1, ch2, one, nine, getSym);
System.out.print(username + "\t " + password + "\n");
out.print(username + "\t" + password + "\n");}

Answer Source

Whatever you a viewing the output in has the tab spacing set to less than the usernames lengths in some cases.

If you use a real programmers editor like Sublime Text and view the invisibles you will see that the \t is there.

If you set the tab spacing longer than the longest username in whatever you are viewing the output in you will see they are there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download