toUpperCase(char) returns
the unaltered character for any character not lower case.
Here is the complete program. Copy it to your editor if you want to save it to a file and run it.
class FSTtester
{
public static void main (String[] args)
{
String inString = null;
String outString = null;
FST fst = new FST();
inString = args[0];
if ( (outString = fst.transform( inString )) != null )
System.out.println("The string is transformed to:" + outString );
else
System.out.println("The string is rejected.");
}
}
class FST
{
public String transform(String str)
{
char current; // the current character
char caps;
int index = 0 ; // index of the current character
String outString = ""; // the output string the FST produces
// (initialized to an empty string)
if ( str == null ) return null; // check for legal argument
while ( index < str.length() )
{
current = str.charAt( index++ ) ;
if ( current >= 'a' && current <= 'z' )
{
caps = Character.toUpperCase( current );
outString += caps ;
}
else
outString += current ;
}
return outString;
}
}
Of course, if you really wanted to convert a string to upper case
you would use the toUpperCase() method,
not write your own.
Here is a run of the program:
C:\CAI\FiniteAutomata>javac FSTtester.java C:\CAI\FiniteAutomata>java FSTtester "A room with A View" The string is transformed to:A ROOM WITH A VIEW C:\CAI\FiniteAutomata>
Is this statement:
String outString = null;
the same as this statement:
String outString = ""; // the string consisting of no characters