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
11 changes: 10 additions & 1 deletion task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ 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 sum = 0;
int currentByte;

while ((currentByte = inputStream.read()) != -1) {
sum = Integer.rotateLeft(sum, 1) ^ currentByte;
}

return sum;
}
}
18 changes: 18 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,23 @@ public static void main(String[] args) throws IOException {
// - направить стандартный вывод программы в файл output.test
// - запустить программу
// - и сравнить получившийся файл output.test с expected.test
int prevByte = -1;
int currentByte;

while ((currentByte = System.in.read()) != -1) {
if (prevByte == 13 && currentByte == 10) {
System.out.write(10);
prevByte = -1;
} else {
if (prevByte != -1) {
System.out.write(prevByte);
}
prevByte = currentByte;
}
}
if (prevByte != -1) {
System.out.write(prevByte);
}
System.out.flush();
}
}
18 changes: 15 additions & 3 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.task03;

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

public class Task03Main {
Expand All @@ -16,6 +15,19 @@ 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);
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuilder result = new StringBuilder();
String currentLine;

while ((currentLine = bufferedReader.readLine()) != null) {
result.append(currentLine);
}
return result.toString();
}
}
14 changes: 13 additions & 1 deletion task04/src/com/example/task04/Task04Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
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 {
// чтобы протестировать свое решение, вам нужно:
// - направить файл input.test в стандартный ввод программы (в настройках запуска программы в IDE или в консоли)
// - запустить программу
// - проверить, что получилось 351.731900
Scanner scanner = new Scanner(System.in);
double sum = 0.0;
while (scanner.hasNext()) {
String token = scanner.next();
try {
double number = Double.parseDouble(token);
sum += number;
} catch (NumberFormatException e) {

System.out.println("0.0");
}
}
System.out.printf(Locale.US,"%.6f", sum);
}
}