import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner DRIn = new Scanner(new FileInputStream("c:/ShortIn.txt"));
while(DRIn.hasNext()) {
String reference = DRIn.nextLine();
System.out.print("\n");
System.out.print(reference+"\n");
for(int d = 0; d < reference.length(); d++) {
String searchString = Character.toString(reference.charAt(d)).trim();
for(int i = 0; i < searchString.length(); i++)
{
char searchChar = searchString.charAt(i);
int count = countChars(searchChar, reference);
reference = reference.replace(searchChar, ' ');
System.out.print("" + searchChar + ", " + count+" ");
}
}
}
DRIn.close();
}
public static int countChars(char searchChar, String reference) {
int count = 0;
for(int i = 0; i < reference.length(); i++) {
if(searchChar == reference.charAt(i)) {
count++;
}
}
return count;
}
}
=== output ===
//why do i have this space????
THE GETTYSBURG ADDRESS
T, 3 H, 1 E, 3 G, 2 Y, 1 S, 3 B, 1 U, 1 R, 2 A, 1 D, 2
4 score and 7 years ago our fathers brought forth on this continent a new
4, 1 s, 4 c, 2 o, 7 r, 6 e, 5 a, 5 n, 6 d, 1 7, 1 y, 1 g, 2 u, 2 f, 2 t, 6 h, 4 b, 1 i, 2 w, 1
nation, conceived in liberty and dedicated to the proposition that all men
n, 7 a, 5 t, 8 i, 7 o, 6 ,, 1 c, 3 e, 7 v, 1 d, 5 l, 3 b, 1 r, 2 y, 1 h, 2 p, 2 s, 1 m, 1
are created equal. Now we are engaged in a great civil war, testing whether
a, 8 r, 6 e, 12 c, 2 t, 5 d, 2 q, 1 u, 1 l, 2 ., 1 N, 1 o, 1 w, 4 n, 3 g, 4 i, 4 v, 1 ,, 1 s, 1 h, 2
that nation or any nation so conceived and so dedicated can long endure.
t, 5 h, 1 a, 7 n, 10 i, 4 o, 7 r, 2 y, 1 s, 2 c, 4 e, 6 v, 1 d, 6 l, 1 g, 1 u, 1 ., 1
We are met on a great battlefield of that war. We have come to dedicate
W, 2 e, 11 a, 8 r, 3 m, 2 t, 8 o, 4 n, 1 g, 1 b, 1 l, 2 f, 2 i, 2 d, 3 h, 2 w, 1 ., 1 v, 1 c, 2
a portion of that field as a final resting-place
a, 6 p, 2 o, 3 r, 2 t, 4 i, 4 n, 3 f, 3 h, 1 e, 3 l, 3 d, 1 s, 2 g, 1 -, 1 c, 1
for those who here gave their lives that that nation might live.
f, 1 o, 4 r, 3 t, 8 h, 7 s, 2 e, 7 w, 1 g, 2 a, 4 v, 3 i, 5 l, 2 n, 2 m, 1 ., 1
It is altogether fitting and proper that we should do this. But in a
I, 1 t, 9 i, 5 s, 3 a, 4 l, 2 o, 4 g, 2 e, 4 h, 4 r, 3 f, 1 n, 3 d, 3 p, 2 w, 1 u, 2 ., 1 B, 1
larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow this ground.
l, 3 a, 7 r, 4 g, 2 e, 10 s, 4 n, 9 ,, 3 w, 4 c, 6 o, 6 t, 6 d, 3 i, 2 h, 2 u, 1 ., 1
The brave men, living and dead who struggled here have consecrated it far above our
T, 1 h, 4 e, 11 b, 2 r, 6 a, 7 v, 4 m, 1 n, 4 ,, 1 l, 2 i, 3 g, 3 d, 5 w, 1 o, 4 s, 2 t, 3 u, 2 c, 2 f, 1
poor power to add or detract. The world will little note nor long remember
p, 2 o, 9 r, 8 w, 3 e, 8 t, 6 a, 2 d, 4 c, 1 ., 1 T, 1 h, 1 l, 6 i, 2 n, 3 g, 1 m, 2 b, 1
what we say here, but it can never forget what they did here.
w, 3 h, 5 a, 4 t, 6 e, 9 s, 1 y, 2 r, 4 ,, 1 b, 1 u, 1 i, 2 c, 1 n, 2 v, 1 f, 1 o, 1 g, 1 d, 2 ., 1
It is for us the living rather to be dedicated here to the unfinished work
I, 1 t, 7 i, 6 s, 3 f, 2 o, 4 r, 5 u, 2 h, 5 e, 9 l, 1 v, 1 n, 3 g, 1 a, 2 b, 1 d, 4 c, 1 w, 1 k, 1
which they who fought here have thus far so nobly advanced. It is rather for
w, 2 h, 9 i, 2 c, 2 t, 5 e, 6 y, 2 o, 5 f, 3 u, 2 g, 1 r, 5 a, 5 v, 2 s, 3 n, 2 b, 1 l, 1 d, 2 ., 1 I, 1
us to be here dedicated to the great task remaining before us--that from
u, 2 s, 3 t, 8 o, 4 b, 2 e, 10 h, 3 r, 5 d, 3 i, 3 c, 1 a, 5 g, 2 k, 1 m, 2 n, 2 f, 2 -, 2
these honored dead we take increased devotion to that cause for which they
t, 7 h, 6 e, 11 s, 3 o, 6 n, 3 r, 3 d, 5 a, 5 w, 2 k, 1 i, 3 c, 3 v, 1 u, 1 f, 1 y, 1
gave the last full measure of devotion--that we here highly resolve that these dead
g, 2 a, 6 v, 3 e, 13 t, 8 h, 7 l, 5 s, 4 f, 2 u, 2 m, 1 r, 3 o, 4 d, 3 i, 2 n, 1 -, 2 w, 1 y, 1
shall not have died in vain, that this nation under God shall have a new birth of
s, 3 h, 7 a, 8 l, 4 n, 7 o, 4 t, 6 v, 3 e, 5 d, 4 i, 6 ,, 1 u, 1 r, 2 G, 1 w, 1 b, 1 f, 1
freedom, and that government of the people, by the people,
f, 2 r, 2 e, 10 d, 2 o, 5 m, 2 ,, 3 a, 2 n, 3 t, 5 h, 3 g, 1 v, 1 p, 4 l, 2 b, 1 y, 1
for the people shall not perish from the earth.
f, 2 o, 4 r, 4 t, 4 h, 5 e, 6 p, 3 l, 3 s, 2 a, 2 n, 1 i, 1 m, 1 ., 1