Hey everyone!
So, I have been given a piece of work to do for College that requires me to format user input. For example:
This is an example of text that will have straight left and right margins after formatting
will transform into:
This..is..an.example
of..text..that..will
have..straight..left
and...right..margins
after.....formatting
The user inputs the width, in the case above being 20. Each line has to therefore be 20 characters long. All spaces are to be replaced with full stops.
I do not want an answer, and just need help to guide me in where I should start! My progress so far results in
This.is.an.example.o
f.text.that.will.hav
e.straight.left.and.
right.margins.after.
formatting..........
Any guidance is much appreciated, I am at a total loss after working on it for about four hours!!
public class Main { public static void main ( String args[]) { System.out.println("Please input the desired length for the text"); int length = BIO.getInt(); System.out.println("Please input the text you wish to edit"); String text = BIO.getLine(); int number = text.length() % length; System.out.println(number); text = text.replace(' ', '.'); int i = 0; while ( i < text.length() ) { for (int x = 0; x < length; x++) { if (i < text.length()) { System.out.print (text.charAt(i)); i = i + 1; } } if (i == text.length()) { for (int y = 0; y < number; y++) { System.out.print("."); } } System.out.println(); } } }