I know very little aboout coding and less of Java
Logic says I should be able to do something like this:

int i;
String taxFileNumber;
System.out.printf(" Enter Tax File Number (TFN): ");
for(i = 0; i < TFN_SIZE; i++)
{
if(i == 3 || i == 7)
{
taxFileNumber.charAt(i) = " ";
}else
{
taxFileNumber = input.next().charAt(i);
}
System.out.println();
}

Howsoever methinks my logic and ability do not sync
Any assistance would be greatly appreciated
TYIA

Recommended Answers

that logic is very lousy indeed.
what if you enter other numbers? your formatting 'll be wrong.
you may rather want to format a String, and check it's size.
if the size = longer than 3, add a space on the 4th last place.
and so on, and so forth.

Jump to Post

All 2 Replies

that logic is very lousy indeed.
what if you enter other numbers? your formatting 'll be wrong.
you may rather want to format a String, and check it's size.
if the size = longer than 3, add a space on the 4th last place.
and so on, and so forth.

Strings in Java are immutable - you cannot change them.
Have a look at StringBuilder which is like a String but you can do stuff like inserting blanks into the middle of it...

Be a part of the DaniWeb community

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