Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package chessboard;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7.  
  8. public class ChessboardOne {
  9.     public static void main (String args[]) {
  10.  
  11.  
  12.     try {
  13.         BufferedReader in = new BufferedReader(new FileReader("D:\\Documents and Settings\\Anthony.PEPSI\\Desktop\\Uni\\Workspace\\Coursework\\Board01.txt"));
  14.         String s;
  15.         while ((s = in.readLine()) != null) {
  16.             int count = 0;
  17.             char charSearch = 'p';
  18.             for (int i = 0; i < s.length(); i++) {
  19.  
  20.                 if( s.charAt(i) == charSearch ) {
  21.                     count++;}}
  22.  
  23.             System.out.println("There is: "+count+" p's in this string.");
  24.         }
  25.         in.close();
  26.     } catch (IOException e) {
  27.     }
  28.  
  29.     }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement