-3

I'm trying to convert one element from array to upper case, but I get an error "cannot find symbol". If I don't use "toUpperCase" it works just fine and the symbol "sentence" works too.

Here's the part that doesnt work:

if (i % 3==0){
    string=string+". "+toUpperCase(array[i].substring(0,1));
}

here's the whole method that works unless i put toUpperCase:

public static String sentences(String[] array){
        String string="";
        for (int i=0;i<array.length;i++){
            if (i % 3==0){
                string=string+". "+toUpperCase(array[i].substring(0,1));
            }
            else if (i % 3!=0){
                sentence=sentence+" "+array[i];
            }
        }

It just finds third word in a sentence and I want to make the first letter of that third word to upper case.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97

3 Answers3

1

toUpperCase() is a method of the String class. So it is:

array[i].substring(0,1).toUpperCase()

But in your case, you could use:

private String capitalize(final String line) {
   return Character.toUpperCase(line.charAt(0)) + line.substring(1);
}

See this post for more info: How to capitalize the first character of each word in a string

Community
  • 1
  • 1
Derlin
  • 9,572
  • 2
  • 32
  • 53
1

toUpperCase() working like below :

  String str = "test";
  System.out.println(str.toUpperCase() );

Output : TEST

Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
0

You can not do something like

string+". "+toUpperCase()

You could if you define a method in that class, but I think what you mean to do is:

string.toUpperCase()
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97