Advertisement
twozniak

testy_bbs

Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.io.Reader;
  6.  
  7. public class test {
  8.  
  9.     public static void main(String[] args) throws FileNotFoundException, Exception {
  10.         InputStream in = new FileInputStream("C:\\Users\\L039\\eclipse-workspace\\test1\\bbs.txt");
  11.         Reader r = new InputStreamReader(in, "UTF-8");
  12.         int intch;
  13.         int counter0 = 0, counter1 = 0, seria = 0, seriaMax = 26;
  14. //      char previous = (char) r.read();
  15.         char compare = '1';
  16. //      System.out.println(previous);
  17.        
  18.         while ((intch = r.read()) != -1) {
  19.             char ch = (char) intch;
  20.             //długiej serii
  21.             if (compare == ch) {
  22.                 seria++;
  23.             } else {
  24. //              previous = ch;
  25.                 seria = 1;
  26.             }
  27.             if (seria > seriaMax)
  28.                 seriaMax = seria;
  29.  
  30.             //pojedynczych bitów
  31.             if (ch == '0') {
  32.                 counter0++;
  33.             } else {
  34.                 counter1++;
  35.             }
  36.         }
  37.  
  38.         System.out.println("Ciągi losowe: \n" + "Number of 0: " + counter0 + "\n" + "Number of 1: " + counter1);
  39.         if (9725 < counter1 && counter1 < 10275)
  40.             System.out.println("\nTest pojedynczych bitów\n" + "9 725 < n1 < 10 275" + " TAK");
  41.         if (seriaMax > 26)
  42.             System.out.println("\nTest serii: NIEPOWODZENIE \n Długość serii: " + seriaMax);
  43.         else
  44.             System.out.println("\nTest długiej serii: POWODZENIE");
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement