This program is supposed to printout all the first letters of the Strings enterned in an Array. Which works.
but when I added some code to convert the first letters to uppercase, there's an error.
I put a comment in the code where the error is.
what's wrong with that part?
import java.util.*;
import static java.lang.Character.*;
import static java.lang.String.*;
public class myfirstarray{
static Scanner scan = new Scanner(System.in);
public static void main (String[]args){
String[] word = new String[5];
String[] str = new String[5];
String str0 , str1, str2,str3, str4 ;
int counter;
System.out.println("Enter 5 words:");
for (counter=0; counter < word.length ; counter++ )
{ word[counter] = scan.nextLine();
System.out.println ("word assigned to word[" + counter + "].");
str[counter] = word[counter];
str[counter].toUpperCase(charAt(0));/* error: cannot find symbol
str[counter].toUpperCase(charAt(0));
^
symbol: method charAt(int)
location: class myfirstarray*/
}
char firstletter0 = word[0].charAt(0);
char firstletter1 = word[1].charAt(0);
char firstletter2 = word[2].charAt(0);
char firstletter3 = word[3].charAt(0);
char firstletter4 = word[4].charAt(0);
System.out.println("\n Entered words are: " + word[0] + " " + word[1] + " " + word[2] + " " + word[3] + " " + word[4] );
System.out.println("\n There first letters are " + firstletter0 + ", " + firstletter1 + ", " + firstletter2 + ", " + firstletter3 + " & " + firstletter4 + " respectively.");
System.out.println("\n words with first letters converted to uppercase: " + str[0] + " " + str[1] + " " + str[2] + " " + str[3] + " " + str[4] );
}
}