#JAVA basics need help for school lab

1 messages · Page 1 of 1 (latest)

hybrid sphinx
#

cant figure out how to check if the string ends in a group of letters or a single letter

fiery citrusBOT
#

<@&987246399047479336> please have a look, thanks.

fiery citrusBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

To check if a string ends in a group of letters or a single letter, you can use the endsWith() method provided by the String class in Java.

Here's an example code snippet to demonstrate how to use endsWith():

public class StringEndsWithExample {
    public static void main(String[] args) {
        String str = "Hello World";
        
        // Check if the string ends with "ld"
        boolean endsWithGroup = str.endsWith("ld");
        System.out.println("Ends with group of letters: " + endsWithGroup);
        
        // Check if the string ends with "d"
        boolean endsWithSingle = str.endsWith("d");
        System.out.println("Ends with single letter: " + endsWithSingle);
    }
}

Output:

Ends with group of letters: true
Ends with single letter: true

In this example, we have a string str which is set to "Hello World". We then use the endsWith() method to check if it ends with either "ld" or "d". The result is stored in boolean variables (endsWithGroup and endsWithSingle) and printed out.

hybrid sphinx
#

its also not going to be hard coded

stiff idol
#

Try writing the code first

hybrid sphinx
#

I dont know how thats why im asking

stiff idol
#

Do you know how to make a String variable called word?

hybrid sphinx
#

yes

#

but how do i check if it ends with a single letter or a group of letters

#

wait im silly

#

never mind sorry

stiff idol
#

You use the functions given to you, in the constructor