32.7k views
1 vote
Write a static boolean method named beginsWithZ. It should accept a String object as a parameter. It should return true if the first character in the String is either of two characters: a capital ‘Z’, or a lowercase ‘z’. (Note: Check the parameter for a null value, and for an empty string. Nulls and empty strings do not start with an ‘z’.)

User Ambirex
by
6.4k points

1 Answer

3 votes

Answer:

public static boolean beginsWithZ(String word) string.length() == 0)

return 0;

if(word.charAt(0) == 'Z'

Step-by-step explanation:

This method is a boolean method, meaning it returns true if the string begins with Z or z and false otherwise. So:

The Java command charAt() let's you find the character at each position of the string, so i use it.

public static boolean beginsWithZ(String word) string.length() == 0)

return 0;

if(word.charAt(0) == 'Z'

User Gigoland
by
6.4k points