0

So i did my code, he asks for the string then i put it, then he tells me what string i put in but for some reason i dont understand he doesnt show the capitalized first letter for each word coverted string.

Here is my code:

import java.io.*;
public class LerString {
public static void main(String[] args) {
boolean stop;
do {
System.out.println("Enter your string");
BufferedReader si = new BufferedReader(
new InputStreamReader(System.in));
String s = null;
try { s = si.readLine(); }
catch(IOException e) { System.out.println("error"); }
System.out.println("You Entered " +s);


stop = s.equals("stop it");
}
while(!stop);


}


static void printCapitalized(String s) {
char ch;
char prevCh;
prevCh = '.';
for ( int i=0 ;  i < s.length();  i++ ) {
ch = s.charAt(i);
if ( Character.isLetter(ch)  &&  ! Character.isLetter(prevCh) )
System.out.print( Character.toUpperCase(ch) );
else
System.out.print( Character.toLowerCase(ch) );
prevCh = ch;
}
System.out.println();
}



}

Any Ideas would be much appreciated

Cheers

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by stultuske
0

Well, you do not call the printCapitalized() method anywhere in your main method, so it's not going to do anything until you call it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.