Last active
September 26, 2016 18:24
-
-
Save dsouzadyn/68c0de2f9698566273504b89db58ed10 to your computer and use it in GitHub Desktop.
Java program for finding character count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class DemoClass { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int upperCaseCount = 0, | |
lowerCaseCount = 0, | |
spacesCount = 0, | |
digitCount = 0, | |
specialCharCount = 0; | |
String data; | |
System.out.print("Enter data: "); | |
Scanner sc = new Scanner(System.in); | |
data = sc.nextLine(); | |
for(char c: data.toCharArray()) { | |
if(Character.isUpperCase(c)) | |
upperCaseCount++; | |
if(Character.isLowerCase(c) && !Character.isSpaceChar(c)) | |
lowerCaseCount++; | |
if(Character.isDigit(c)) | |
digitCount++; | |
if(Character.isSpaceChar(c)) | |
spacesCount++; | |
} | |
specialCharCount = data.length() - (upperCaseCount + lowerCaseCount + digitCount + spacesCount); | |
System.out.println("Upper case characters: " + upperCaseCount); | |
System.out.println("Lower case characters: " + lowerCaseCount); | |
System.out.println("Space characters: " + spacesCount); | |
System.out.println("Digit characters: " + digitCount); | |
System.out.println("Special characters: " + specialCharCount); | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment