Skip to main content

Practice Code Structure

Section 1.14 Fill-in-the-blank

Checkpoint 1.14.1.

The wordCheck() function takes a String input and returns a String. Complete the code by filling in the blanks underneath so that it returns "Valid" only when the input starts with capital ’A’ and ends with ’c’. Otherwise, it returns "Not valid".
public static String wordCheck(String word) {
    int lastCharIndex = word.length() - 1;
    if (-------Blank 1------) {
        return "Not valid"; 
    }   
    if (--------Blank 2------) {
        return "Valid"; 
    } 
    return "Not valid";
}
Here are some code segments that you should use to complete the wordCheck(). However, you may need to conjoin some of these code segments using appropriate operators.
  • word.charAt(0) == 'A'
  • word.charAt(lastCharIndex) == 'c'
  • word.length() < 2
Write your responses here:
Blank 1:
Blank 2:
Hint.
The first blank needs only one condition and the second one needs conjunction of two conditions.
You have attempted 1 of 2 activities on this page.