Java: Find the sequences of one upper case letter followed by lower case letters
4. Match Uppercase Followed by Lowercase
Write a Java program to find the sequence of one upper case letter followed by lower case letters.
Sample Solution:
Java Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println(validate("Java"));
System.out.println(validate("java"));
System.out.println(validate("javA"));
System.out.println(validate("JAVa"));
System.out.println(validate("Ja"));
System.out.println(validate("aJ"));
}
public static String validate(String text) {
if (text.matches("[A-Z][a-z]+$"))
return "Found a match!";
else
return "Not matched!";
}
}
Sample Output:
Found a match! Not matched! Not matched! Not matched! Found a match! Not matched!
Pictorial Presentation:
Flowchart :
For more Practice: Solve these Related Problems:
- Write a Java program to extract all substrings that start with a single uppercase letter followed by one or more lowercase letters.
- Write a Java program to verify if a given word is capitalized properly with one uppercase followed by lowercase letters.
- Write a Java program to list all words from a paragraph that match the uppercase-lowercase pattern using regex.
- Write a Java program to implement a method that filters out words not following the pattern of one uppercase followed by only lowercase letters.
Go to:
PREV : Match Lowercase with Underscore.
NEXT : Match 'p...q' Pattern.
Java Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.