Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ public static void main(String[] args) throws IOException {
}

public static int checkSumOfStream(InputStream inputStream) throws IOException {
// your implementation here
return 0;

if (inputStream == null) {
throw new IllegalArgumentException();
}

int result = 0;
int b, c;

while ((b = inputStream.read()) != -1) {
c = Integer.rotateLeft(result, 1);
result = c ^ b;
}

return result;
}
}
}
19 changes: 19 additions & 0 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,24 @@ public static void main(String[] args) throws IOException {
// - направить стандартный вывод программы в файл output.test
// - запустить программу
// - и сравнить получившийся файл output.test с expected.test

int currentByte;
int nextByte;

currentByte = System.in.read();

while (currentByte != -1) {
nextByte = System.in.read();

if (currentByte == 13 && nextByte == 10) {
currentByte = nextByte;
continue;
}

System.out.write(currentByte);

currentByte = nextByte;
}
System.out.flush();
}
}
13 changes: 11 additions & 2 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class Task03Main {
Expand All @@ -15,7 +16,15 @@ public static void main(String[] args) throws IOException {
}

public static String readAsString(InputStream inputStream, Charset charset) throws IOException {
// your implementation here
return "";
if (inputStream == null || charset == null) {
throw new IllegalArgumentException();
}
InputStreamReader reader = new InputStreamReader(inputStream, charset);
StringBuilder result = new StringBuilder();
int c;
while ((c = reader.read()) != -1) {
result.append((char) c);
}
return result.toString();
}
}
14 changes: 12 additions & 2 deletions task04/src/com/example/task04/Task04Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.task04;

import java.io.IOException;
import java.util.Locale;
import java.util.Scanner;

public class Task04Main {
public static void main(String[] args) throws IOException {
Expand All @@ -9,6 +11,14 @@ public static void main(String[] args) throws IOException {
// - запустить программу
// - проверить, что получилось 351.731900

System.out.println("0.0");
Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
double result = 0;

while (scanner.hasNextDouble()) {
double token = scanner.nextDouble();
result += token;
}

System.out.printf(Locale.US,"%.6f", result);
}
}
}