Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.wit.cs.comp1000;
- import java.util.Scanner;
- /**
- *
- * @author
- *
- */
- public class PA7b {
- /**
- * Program execution point: input text via console input, output counts for each
- * letter found in the input (case-insensitive)
- *
- * @param args command-line arguments (ignored)
- */
- public static void main(String[] args) {
- final int[] counter = new int[26];
- final Scanner S = new Scanner(System.in);
- System.out.printf("Enter text: ");
- while (S.hasNext()) {
- final String s = S.next();
- for (int i = 0; i < s.length(); i++) {
- final char c = s.charAt(i);
- if (c >= 'A' && c <= 'Z') {
- counter[c - 'A']++;
- } else if (c >= 'a' && c <= 'z') {
- counter[c - 'a']++;
- }
- }
- }
- boolean tfstatement = false;
- for (int i = 0; i < counter.length; i++) {
- if (counter[i] > 0) {
- System.out.printf("%c: %d%n", ('A' + i), counter[i]);
- tfstatement = true;
- }
- }
- if (!tfstatement) {
- System.out.printf("%n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement