Computer Applications

Define a class to accept a String and print if it is a Super String or not. A String is Super if the number of uppercase letters are equal to the number of lowercase letters. [Use Character and String methods only]
Example: “COmmITmeNt”
Number of uppercase letters = 5
Number of lowercase letters = 5
String is a Super String

Java

Java String Handling

14 Likes

Answer

import java.util.Scanner;
class SuperString{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the string: ");
        String s = in.nextLine();
        int upper = 0;
        int lower = 0;
        int l = s.length();
        for(int i = 0; i < l; i++){
            char ch = s.charAt(i);
            if(Character.isUpperCase(ch))
                upper++;
            else if(Character.isLowerCase(ch))
                lower++;
        }
        if(upper == lower)
            System.out.println("String is a Super String");
        else
            System.out.println("String is not a Super String");
    }
}

Output

Answered By

6 Likes


Related Questions