0% found this document useful (0 votes)
2 views1 page

Count

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Count

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Q.

Write A Java Program To Count The Number Of Upper Case, Lower Case, Blank Space
And Digits In A String.

import java.util.*;

class Count
{
public static void main(String args[])
{
String str = "Shridhar Joshi";
int upper = 0, lower = 0, number = 0, space = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if (ch >= 'a' && ch <= 'z')
lower++;
else if (ch >= '0' && ch <= '9')
number++;
else
space++;
}

System.out.println("Lower case letters : " + lower);


System.out.println("Upper case letters : " + upper);
System.out.println("Number : " + number);
System.out.println("Space : " + space);
}
}

OUTPUT :

Lower case letters : 11


Upper case letters : 2
Number : 0
Space : 1

You might also like