Last active
August 29, 2015 14:10
-
-
Save JaisonBrooks/b00310f5bbd094b16cb1 to your computer and use it in GitHub Desktop.
pretty clevor
This file contains hidden or 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
public static void main(String[] args) { | |
String inputStr; | |
String charInput; | |
int totalCount = 0; | |
int index = 0; | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Enter text to be searched: "); | |
inputStr = scanner.nextLine(); | |
System.out.println("Enter a character: "); | |
charInput = scanner.nextLine(); | |
while (index > -1) { | |
index = inputStr.indexOf(charInput, index + 1); | |
if (index > -1) { | |
totalCount++; | |
} | |
} | |
System.out.println("Number of Letter (" + charInput + ") Occurrences = " + totalCount); | |
String indexes = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase(); | |
int[] count = new int[indexes.length()]; | |
for (int i = 0; i < inputStr.length(); i++) { | |
int newIndex = indexes.indexOf(inputStr.charAt(i)); | |
if (newIndex < 0) | |
continue; | |
count[newIndex]++; | |
} | |
for (int i = 0; i < indexes.length(); i++) { | |
System.out.println(String.format("%s (%d) %s", | |
indexes.charAt(i), | |
count[i], | |
new String(new char[count[i]]).replace('\0', '*'))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment