Browse Source

docs(SortArgs) - Fix bug in ExerciseRunner (#2138)

Restores the default `System.out` to fix result printing

`System.out` was changed to a custom `printStream`, so `System.out.println(output.equals("1 2 3 4\n"));` printed `true` or `false` to this `printStream` and not the default `System.out`. This causes console output to be empty.
pull/2483/head
Maxim Mikhailov 9 months ago committed by GitHub
parent
commit
49d02bfdee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      subjects/java/piscine/SortArgs/README.md

9
subjects/java/piscine/SortArgs/README.md

@ -28,8 +28,13 @@ public class ExerciseRunner {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
var defaultOut = System.out;
System.setOut(printStream);
SortArgs.sort(new String[]{"4","2","1","3"});
SortArgs.sort(new String[]{"4", "2", "1", "3"});
System.setOut(defaultOut);
String output = outputStream.toString();
System.out.println(output.equals("1 2 3 4\n"));
}
@ -51,4 +56,4 @@ $
[Conditional statement](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html)
[String](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html)
[Array](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html)
[File](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html)
[File](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html)

Loading…
Cancel
Save