All pastes #396744 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-15 23:55 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.println("" + searchChar + ", " + count); // this is what give me the most problem look at the output of this method
	                     
	                    
	                }
	                
	            }
	            
	        }
	      
	        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;
	    }
	    
	}



Current output
--------------

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
.....