UPDATE
Been spending about half my night on it but im still confused on where to add a loop or something. From my current progress below i understand that the if statement is finishing and then the next word is being called before another . is generated but i dont know where to move anything. Everything i have tried has failed
Results:
[C] Please wait for processing
[C] Elapsed time to process request 0.792 seconds
DataSet 1
----------Compilation output--------------------------------------------
javac Main.java
classes in application
class Main
----------Data used as input was----------------------------------------
20
This is an example
of text that will
have straight left
and right margins
after formatting
END
----------Expected answer was-------------------------------------------
This..is..an.example
of..text..that..will
have..straight..left
and...right..margins
after.....formatting
----------Your answer however was [ Excluding lines containing a # ] ---
This..is..an.example
of..text..that.will
have..straight..left.
and..right..margins.
after..formatting..
----------Differences are-----------------------------------------------
2,5c2,5
< of..text..that.will
< have..straight..left.
< and..right..margins.
< after..formatting..
---
> of..text..that..will
> have..straight..left
> and...right..margins
> after.....formatting
------------------------------------------------------------------------
[S] Sorry exercise ci101.java/3.5 was not completed successfully
class Main
{
public static void main( String args[] )
{
System.out.print("#Enter Width Of Paragraph:");
int width = BIO.getInt();
System.out.print("#Enter Word Here:");
String text = BIO.getString();
char ch = ' ';
int numberofspaces = count( text, ch);
int numberofspacesadd = width - text.length();
int spaceratio = numberofspacesadd % numberofspaces;
String[] words = text.split(" ");
while ( ! text.equals( "END" )){
for (int i = 0; i<words.length; i++){
System.out.print( words[i]);
if ( i < numberofspaces ){
System.out.print( "." );
}
if ( i < spaceratio ){
System.out.print( "." );}
}
System.out.println();
System.out.print("#Enter Word Here:");
text = BIO.getString();
words = text.split(" ");
}
}
public static int count( String s, char c )
{
String str = s.toLowerCase();
int count = 0;
for ( int i = 0; i < str.length(); i++ )
{
if ( str.charAt(i) == c )
count++;
}
return count;
}
}