JAVA 10
CharCount and charDist from Homework 2 Guest on 19th September 2022 04:12:29 AM
  1. public class CharCountDist {
  2.     public static void main(String[] args) {
  3.         //charDist("ABCD","A BAD DAY");
  4.         charDist("ABCDEIKLMNOPQRSVWXYZ", "XEWLOBDROYBISCDYMYWZEDOBCMSOXMOKCNSPPOBOXDSKVOAEKDSYXCKBODYOXQSXOOBSXQ");
  5.     }
  6.  
  7.     //char count in a string
  8.     public static int charCount(char C, String text) {
  9.         char[] strArr;
  10.         strArr = text.toCharArray();
  11.         int count = 0;
  12.         for (char c : strArr) {
  13.             if (C == c) {
  14.                 count++;
  15.             }
  16.         }
  17.         return count;
  18.     }
  19.  
  20.     //handles a list of chars to compare with charCount()
  21.     public static void charDist(String list, String text) {
  22.         char[] strArr;
  23.         strArr = list.toCharArray();
  24.         for (char c : strArr) {
  25.             System.out.println(c + " : " + charCount(c, text));
  26.         }
  27.     }
  28.  
  29. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.