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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
