Advertisement
KeepCoding

Draw Java Exam November 5th

Nov 28th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class JavaDraw {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(console.nextLine());
  8.         int pictureLength = 3 * n + 6;
  9.  
  10.         //top part (steam)
  11.         for (int row = 0; row < n; row++) {
  12.             System.out.print(returnStr(n, " "));
  13.             System.out.println("~ ~ ~");
  14.         }
  15.         //above java
  16.         System.out.println(returnStr(pictureLength - 1, "="));
  17.         //middle part
  18.         int middleHeight = n - 2;
  19.         int javaRow = n / 2;
  20.         for (int row = 1; row <= middleHeight; row++) {
  21.             System.out.print("|");
  22.             System.out.print(returnStr(n, "~"));
  23.  
  24.             if (row != javaRow) {
  25.                 System.out.print(returnStr(4, "~"));
  26.             } else {
  27.                 System.out.print("JAVA");
  28.             }
  29.  
  30.             System.out.print(returnStr(n, "~"));
  31.             System.out.print("|");
  32.             System.out.print(returnStr(n - 1, " "));
  33.             System.out.println("|");
  34.         }
  35.         //below java
  36.         System.out.println(returnStr(pictureLength - 1, "="));
  37.         //bottom half
  38.         int bottomHalfHeight = n;
  39.         for (int row = 0; row < n; row++) {
  40.             System.out.print(returnStr(row, " "));
  41.             System.out.print("\\");
  42.             System.out.print(returnStr((2 * n + 4) - 2 * row, "@"));
  43.             System.out.println("/");
  44.         }
  45.         //bottom part
  46.         System.out.print(returnStr(2 * n + 4 + 2, "="));
  47.         //main ends here
  48.     }
  49.  
  50.     static String returnStr(int count, String character) {
  51.         StringBuilder sb = new StringBuilder();
  52.         for (int i = 0; i < count; i++) {
  53.             sb.append(character);
  54.         }
  55.         return sb.toString();
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement