-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathTask01Main.java
More file actions
30 lines (22 loc) · 942 Bytes
/
Task01Main.java
File metadata and controls
30 lines (22 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.example.task01;
import java.io.IOException;
import java.io.InputStream;
public class Task01Main {
public static void main(String[] args) throws IOException {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:
/*
System.out.println(checkSumOfStream(new ByteArrayInputStream(new byte[]{0x33, 0x45, 0x01})));
*/
}
public static int checkSumOfStream(InputStream inputStream) throws IOException {
// your implementation here
if (inputStream == null) throw new IllegalArgumentException();
int sum = 0;
int currentByte;
while ((currentByte = inputStream.read()) != -1) {
sum = Integer.rotateLeft(sum, 1) ^ currentByte;
}
return sum;
}
}