All pastes #396751 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-16 00:03 UTC
rendered paste body


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.println(reference);
	      
	            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 ===
THE GETTYSBURG ADDRESS
T, 3H, 1E, 3G, 2Y, 1S, 3B, 1U, 1R, 2A, 1D, 24 score and 7 years ago our fathers brought forth on this continent a new
4, 1s, 4c, 2o, 7r, 6e, 5a, 5n, 6d, 17, 1y, 1g, 2u, 2f, 2t, 6h, 4b, 1i, 2w, 1nation, conceived in liberty and dedicated to the proposition that all men
n, 7a, 5t, 8i, 7o, 6,, 1c, 3e, 7v, 1d, 5l, 3b, 1r, 2y, 1h, 2p, 2s, 1m, 1are created equal. Now we are engaged in a great civil war, testing whether
a, 8r, 6e, 12c, 2t, 5d, 2q, 1u, 1l, 2., 1N, 1o, 1w, 4n, 3g, 4i, 4v, 1,, 1s, 1h, 2that nation or any nation so conceived and so dedicated can long endure.
t, 5h, 1a, 7n, 10i, 4o, 7r, 2y, 1s, 2c, 4e, 6v, 1d, 6l, 1g, 1u, 1., 1We are met on a great battlefield of that war. We have come to dedicate
W, 2e, 11a, 8r, 3m, 2t, 8o, 4n, 1g, 1b, 1l, 2f, 2i, 2d, 3h, 2w, 1., 1v, 1c, 2a portion of that field as a final resting-place
a, 6p, 2o, 3r, 2t, 4i, 4n, 3f, 3h, 1e, 3l, 3d, 1s, 2g, 1-, 1c, 1for those who here gave their lives that that nation might live.
f, 1o, 4r, 3t, 8h, 7s, 2e, 7w, 1g, 2a, 4v, 3i, 5l, 2n, 2m, 1., 1It is altogether fitting and proper that we should do this. But in a
I, 1t, 9i, 5s, 3a, 4l, 2o, 4g, 2e, 4h, 4r, 3f, 1n, 3d, 3p, 2w, 1u, 2., 1B, 1larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow this ground.
l, 3a, 7r, 4g, 2e, 10s, 4n, 9,, 3w, 4c, 6o, 6t, 6d, 3i, 2h, 2u, 1., 1The brave men, living and dead who struggled here have consecrated it far above our
T, 1h, 4e, 11b, 2r, 6a, 7v, 4m, 1n, 4,, 1l, 2i, 3g, 3d, 5w, 1o, 4s, 2t, 3u, 2c, 2f, 1poor power to add or detract. The world will little note nor long remember
p, 2o, 9r, 8w, 3e, 8t, 6a, 2d, 4c, 1., 1T, 1h, 1l, 6i, 2n, 3g, 1m, 2b, 1what we say here, but it can never forget what they did here.
w, 3h, 5a, 4t, 6e, 9s, 1y, 2r, 4,, 1b, 1u, 1i, 2c, 1n, 2v, 1f, 1o, 1g, 1d, 2., 1It is for us the living rather to be dedicated here to the unfinished work
I, 1t, 7i, 6s, 3f, 2o, 4r, 5u, 2h, 5e, 9l, 1v, 1n, 3g, 1a, 2b, 1d, 4c, 1w, 1k, 1which they who fought here have thus far so nobly advanced. It is rather for
w, 2h, 9i, 2c, 2t, 5e, 6y, 2o, 5f, 3u, 2g, 1r, 5a, 5v, 2s, 3n, 2b, 1l, 1d, 2., 1I, 1us to be here dedicated to the great task remaining before us--that from
u, 2s, 3t, 8o, 4b, 2e, 10h, 3r, 5d, 3i, 3c, 1a, 5g, 2k, 1m, 2n, 2f, 2-, 2these honored dead we take increased devotion to that cause for which they
t, 7h, 6e, 11s, 3o, 6n, 3r, 3d, 5a, 5w, 2k, 1i, 3c, 3v, 1u, 1f, 1y, 1gave the last full measure of devotion--that we here highly resolve that these dead
g, 2a, 6v, 3e, 13t, 8h, 7l, 5s, 4f, 2u, 2m, 1r, 3o, 4d, 3i, 2n, 1-, 2w, 1y, 1shall not have died in vain, that this nation under God shall have a new birth of
s, 3h, 7a, 8l, 4n, 7o, 4t, 6v, 3e, 5d, 4i, 6,, 1u, 1r, 2G, 1w, 1b, 1f, 1freedom, and that government of the people, by the people,
f, 2r, 2e, 10d, 2o, 5m, 2,, 3a, 2n, 3t, 5h, 3g, 1v, 1p, 4l, 2b, 1y, 1for the people shall not perish from the earth.
f, 2o, 4r, 4t, 4h, 5e, 6p, 3l, 3s, 2a, 2n, 1i, 1m, 1., 1