Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class practice {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- String top = repeatStr("/", (n + 1) - n) + repeatStr("^", n / 2) + repeatStr("\\", (n + 1) - n);
- if (n < 3 || n > 1000){
- System.out.println("Wrong input!");
- return;
- }
- if (n < 5) {
- System.out.println(top + top);
- } else {
- System.out.println(top + repeatStr("_", n / 2) + top);
- }
- for (int i = 0; i < (n - 2) - 1; i++) {
- if (n < 5){
- System.out.println("|" + repeatStr(" ",n-1) + repeatStr(" ",n-1) + "|");
- } else {
- System.out.print("|" + repeatStr(" ",n/ 2));
- System.out.print(repeatStr(" ",n / 2));
- System.out.println(repeatStr(" ",(n/2)+2) + "|");
- }
- }
- String midBottom = repeatStr("_", n / 2);
- if (n < 5){
- System.out.println("|" + repeatStr(" ",(n/2)+1)+ repeatStr(" ",(n/2)+1) + "|");
- } else {
- System.out.println("|" + repeatStr(" ",(n +2)/2) + midBottom + repeatStr(" ",(n+2)/2) + "|");
- }
- String floor = "\\" + repeatStr("_", (n / 2)) + "/";
- if (n < 5) {
- System.out.println(floor + floor);
- } else {
- System.out.println(floor + repeatStr(" ", n / 2) + floor);
- }
- }
- static String repeatStr(String str, int count){
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < count; i++) {
- sb.append(str);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment