Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.Reader;
- public class test {
- public static void main(String[] args) throws FileNotFoundException, Exception {
- InputStream in = new FileInputStream("C:\\Users\\L039\\eclipse-workspace\\test1\\bbs.txt");
- Reader r = new InputStreamReader(in, "UTF-8");
- int intch;
- int counter0 = 0, counter1 = 0, seria = 0, seriaMax = 26;
- // char previous = (char) r.read();
- char compare = '1';
- // System.out.println(previous);
- while ((intch = r.read()) != -1) {
- char ch = (char) intch;
- //długiej serii
- if (compare == ch) {
- seria++;
- } else {
- // previous = ch;
- seria = 1;
- }
- if (seria > seriaMax)
- seriaMax = seria;
- //pojedynczych bitów
- if (ch == '0') {
- counter0++;
- } else {
- counter1++;
- }
- }
- System.out.println("Ciągi losowe: \n" + "Number of 0: " + counter0 + "\n" + "Number of 1: " + counter1);
- if (9725 < counter1 && counter1 < 10275)
- System.out.println("\nTest pojedynczych bitów\n" + "9 725 < n1 < 10 275" + " TAK");
- if (seriaMax > 26)
- System.out.println("\nTest serii: NIEPOWODZENIE \n Długość serii: " + seriaMax);
- else
- System.out.println("\nTest długiej serii: POWODZENIE");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement