fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.stream.*;
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. final class Rectangle {
  9.  
  10. private final double width;
  11. private final double height;
  12.  
  13. public Rectangle(final double width, final double height) {
  14. this.width = width;
  15. this.height = height;
  16. }
  17.  
  18. public double square() {
  19. return width * height;
  20. }
  21.  
  22. @Override
  23. public String toString() {
  24. return String.format("%s{ width = %f ; height = %f }",
  25. getClass().getSimpleName(), width, height);
  26. }
  27. }
  28.  
  29. final class Circle {
  30.  
  31. private final double radius;
  32.  
  33. public Circle(final double radius) {
  34. this.radius = radius;
  35. }
  36.  
  37. public double square() {
  38. return Math.PI * radius * radius;
  39. }
  40.  
  41. @Override
  42. public String toString() {
  43. return String.format("%s{ radius = %f }",
  44. getClass().getSimpleName(), radius);
  45. }
  46. }
  47.  
  48. /* Name of the class has to be "Main" only if the class is public. */
  49. class Ideone {
  50.  
  51. private static void printSquares(final ?... figures) {
  52. Stream.of(figures).forEach(f ->
  53. System.out.printf("%s square = %f%n", f.toString(), f.square()));
  54. }
  55.  
  56. public static void main (String[] args) throws java.lang.Exception {
  57. printSquares(new Rectangle(3, 4), new Circle(2));
  58. }
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:51: error: illegal start of type
	private static void printSquares(final ?... figures) {
	                                       ^
Main.java:51: error: ')' expected
	private static void printSquares(final ?... figures) {
	                                        ^
Main.java:51: error: ';' expected
	private static void printSquares(final ?... figures) {
	                                           ^
Main.java:51: error: illegal start of type
	private static void printSquares(final ?... figures) {
	                                                   ^
Main.java:51: error: <identifier> expected
	private static void printSquares(final ?... figures) {
	                                                    ^
Main.java:51: error: ';' expected
	private static void printSquares(final ?... figures) {
	                                                      ^
Main.java:52: error: illegal start of type
		Stream.of(figures).forEach(f ->
		      ^
Main.java:52: error: <identifier> expected
		Stream.of(figures).forEach(f ->
		                 ^
Main.java:52: error: ';' expected
		Stream.of(figures).forEach(f ->
		                  ^
Main.java:56: error: class, interface, or enum expected
	public static void main (String[] args) throws java.lang.Exception {
	              ^
Main.java:58: error: class, interface, or enum expected
	}
	^
11 errors
stdout
Standard output is empty