fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. int height = new Scanner(System.in).nextInt();
  6. printCross(height);
  7. }
  8.  
  9. private static void printCross(int height) {
  10. for (int i = 0; i < height; i++) {
  11. StringBuilder sb = getEmptySbWithLengthOfN(height);
  12. sb.setCharAt(i, 'X');
  13. sb.setCharAt(height - i - 1, 'X');
  14. System.out.println(sb);
  15.  
  16. }
  17. }
  18.  
  19. private static StringBuilder getEmptySbWithLengthOfN(int height) {
  20. StringBuilder sb = new StringBuilder("");
  21. for (int i = 0; i < height; i++) {
  22. sb.append(" ");
  23. }
  24. return sb;
  25. }
  26.  
  27. private static void printNspaces(int n) {
  28. for (int i = 0; i < n; i++) {
  29. System.out.print(" ");
  30. }
  31. }
  32. }
Runtime error #stdin #stdout #stderr 0.15s 321280KB
stdin
s
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.InputMismatchException
	at java.util.Scanner.throwFor(Scanner.java:864)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Main.main(Main.java:5)