हिंदी

Write a program for the following. Input a string and count the number of non alphabetic characters in it.

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Input a string and count the number of non alphabetic characters in it.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clTask
{
   void main()
   {
       String s1 = """;
       Scanner sc = new Scanner(System.in);
       char ch1, ch2;
       int count = 0;
       System.out.print(" Enter a sentence : ");
       s1 = sc.nextLine();
       for(int j = 0; j <= s1.length() -1; j++)
       {
           ch1 = s1.charAt(j);
           if(ch1 >= 'A' && ch1 <='Z' || ch1 >= 'a' && ch1 <='z')
           {
           }
           else
           {
              count++;
           }
       }
       System.out.println("Number of Non-alphabets is: "+ count);
   }
}

Output:

Enter a sentence : 27/F, MH Lane, Kol - 700 046

Number of Non-alphabets is : 19

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 10: String Handling - Exercises [पृष्ठ २४८]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 10 String Handling
Exercises | Q 4. (d) | पृष्ठ २४८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×