Skip to content

Instantly share code, notes, and snippets.

@jabrena
Created July 23, 2022 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabrena/4c94d533f4d7dcb7ca9a37850ff05d64 to your computer and use it in GitHub Desktop.
Save jabrena/4c94d533f4d7dcb7ca9a37850ff05d64 to your computer and use it in GitHub Desktop.
import java.util.stream.IntStream;
public class XDemo {
public static void main(String[] args) {
int r = 16;
IntStream.rangeClosed(-r, r)
.map(Math::abs)
.peek(i -> IntStream.rangeClosed(-r, r)
.map(Math::abs)
// printing a kind of thick circle,
// thin circle and cross in the center
.mapToObj(j -> i == j && i < r/3 || // cross
// outer thick circle
Math.abs(i*i + j*j - r*r/1.3) < 4*r ||
// inner thin circle
Math.abs(i*i + j*j - r*r/4) < r
// cast to String
? ""
// two random ASCII punctuation
// symbols: !"#$%&'()*+,-./
+ (char) (33 + Math.random() * 15)
+ (char) (33 + Math.random() * 15)
// two whitespaces
: " ")
.forEach(System.out::print))
.forEach(i -> System.out.println());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment