Have the function LetterCapitalize(str) take the str parameter being
passed and capitalize the first letter of each word. Words will be separated
by only one space.
Use the Parameter Testing feature in the box below to test your code with
different arguments.
package demo5;
import java.util.Scanner;
class Test3 {
public static String LetterCapitalize(String str) {
str.trim();
int wordNum=1;
boolean flag=false;
String str2="";
for(int i=0;i<str.length();i++){
char indexword=str.charAt(i);
if(i==0 || flag==true){
if(indexword>='a' && indexword<='z'){
str2+=(char)(indexword-32);
}else{
str2+=indexword;
}
flag=false;
}else if(indexword==' '){
str2+=' ';
flag=true;
}else{
str2+=indexword;
flag=false;
}
}
return str2;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(LetterCapitalize(s.nextLine()));
}
}