हिंदी

Define a class to accept a String and print the number of digits, alphabets and special characters in the string. Example: S = "KAPILDEV@83" - Computer Applications

Advertisements
Advertisements

प्रश्न

Define a class to accept a String and print the number of digits, alphabets and special characters in the string.

Example: S = "KAPILDEV@83"
Output: Number of digits - 2 '
Number of Alphabets - 8
Number of Special characters - 1
संक्षेप में उत्तर
Advertisements

उत्तर

import jaya.util.*; 
public class CountAlpDigiSpl  {
   public static void main(String[] args) {
         String aldisp_str; 
         int i, alph, digi, spl; 
         alph = digi = spl = 0; 
         char ch;·'
         Scanner sc= new Scanner(System.in);
         System.out.print("\nPlease Enter Alpha Numeric Special String :
         ");
          aldisp_str = sc.nextLine();
          for(i = 0; i < aldisp_str.length(); i++)
          {
                 ch= aldisp_str.charAt(i);
                 if(ch >= 'a' && ch<= 'z' | | ch >= 'A' &&
                 ch <= 'Z' ) {
                       alph++;
                 }
                 else if(ch >= '0' && ch<= '9') {
                      digi++;
                 }
                 else {
                    spl++;
               }
         }
      System.out.println("\nNumber of Alphabet
      Characters = " + alph);
      System.out.println("Number of Digit
      characters. = " + digi);
      System.out.println("Number of Special
      Characters = " + spl);
    }
}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Official

संबंधित प्रश्न

Write the return data type of the following function:

endsWith( )


Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for the name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”. 
Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example

Country Name: INDIA     Output: INDIA-TAJMAHAL
Country Name: USA        Output: Sorry Not Found!


Give the output of the following string methods.

"MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')


Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.


The String class method to join two strings is ______.


The output of the function "COMPOSITION". substring(3, 6):


Give the output of the following String class method:

"COMMENCEMENT".lastIndexOf('M')

The output of the statement "CONCENTRATION" indexOf('T') is ______.


The output of the statement "talent". compareTo("genius") is ______.


Consider the array given below:

char ch[]={'A','E','I','O','U'};

Write the output of the following statements:

System.out.println(ch[0]*2);;

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×