Advertisement
skipter

Parallelepiped - Drawing with Loops / Java Basics

Apr 22nd, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.  
  5.         Scanner input = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(input.nextLine());
  8.  
  9.         System.out.println("+" + repeatString("~", n - 2) + "+" + repeatString(".", n * 2 + 1));
  10.         for (int i = 0; i < n * 2 + 1; i++) {
  11.             System.out.println("|" + repeatString(".", i) + "\\" + repeatString("~", n - 2) + "\\" + repeatString(".", (n * 2) - i));
  12.         }
  13.         for (int i = 0; i < n * 2 + 1; i++) {
  14.             System.out.println(repeatString(".", i) + "\\" + repeatString(".",(n * 2) - i) + "|" + repeatString("~", n - 2) + "|");
  15.         }
  16.         System.out.println(repeatString(".", n * 2 + 1) + "+" + repeatString("~", n - 2) + "+");
  17.  
  18.        
  19.  
  20.     }
  21.     public static String repeatString(String str, int counter) {
  22.         String text = "";
  23.         for (int i = 0; i < counter; i++) {
  24.             text += str;
  25.         }
  26.         return text;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement