Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I keep on getting this error message and I don't know how to fix it.

Main.java:19: error: class expected
char ch = char.toLowerCase;
^
1 error

This is my code, it would be nice for someone to help if possible

Java
public class Main 
{
    public static void main (String[]args) 
    {
        String aString = "HELP!! I need to get 37 things DONE today!!";
        int numLetters = 0;
        int stringLength = aString.length;
        System.out.println ("In all lowercase, the sentence is: ");
        for (int i = 0; i < length; i++)
        {
            char ch = char.toLowerCase;
            aString.charAt (length);
            System.out.print (ch);
            if (Character.isLetter ())
            numLetters++;
            }
        System.out.println ();
        System.out.println ("The number of CHARACTERS in the string is " + numLetters);
        System.out.println ("The number of LETTERS is " + stringLength);
    }
}


What I have tried:

I have tried multiple things such as rewriting the line multiple times as possible but have forgotten most of them, any and all suggests will be used.
Posted
Updated 17-Mar-22 17:10pm
v2

1 solution

At first glance use the length() method to get the length of string.
Java
int stringLength = aString.length();
Secondly, Character class is used to convert a chat into upper/lower case. Use Character class method with argument. like
Java
for (int i = 0; i < stringLength; i++) 
{
        char ch = Character.toLowerCase(aString.charAt(i));
        System.out.print (ch);
        if (Character.isLetter(aString.charAt(i)))
            numLetters++;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900