Print uppercase & lowercase letters separately

Q. Write a Java program to find the uppercase and lowercase element in the given string and print it separately.

Answer:

There are isUpperCase() and isLowerCase() methods available in String class to check the upper case and lower case characters respectively.

UpperCaseLowerCase.java

import java.util.*;
class UpperCaseLowerCase
{
     public static void main(String[] args)
     {
          int count = 0;
          Scanner scn = new Scanner(System.in);
          System.out.print("Enter a string: ");
          String str = scn.nextLine();
          System.out.println("Upper case characters: ");
          for (int i = 0; i< str.length(); i++ )
          {
               if (Character.isUpperCase(str.charAt(i)))
               {
                    System.out.print(str.charAt(i)+", ");
               }
          }
          System.out.println("\nLower case characters: ");
          for (int i = 0; i< str.length(); i++ )
          {
               if (Character.isLowerCase(str.charAt(i)))
               {
                    System.out.print(str.charAt(i)+", ");
               }
          }
     }
}


Output:

uppercase lowercase