Advertisement
desislava_topuzakova

Triangle

Oct 15th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Triangle {
  3.     public static void main(String[] args) {
  4.         Scanner scanner=new Scanner(System.in);
  5.         int n=Integer.parseInt(scanner.nextLine());
  6.         int p=1;
  7.         int m=n;
  8.         int q=n;
  9.         int c=n;
  10.         int en=1;
  11.         int z=0;
  12.         int s=n;
  13.         System.out.println(repeatStr("#",4*n+1));
  14.         z++;//full row
  15.  
  16.         for (int i = 0; i <n/2 ; i++) {
  17.             System.out.print(repeatStr(".",p));
  18.             System.out.print(repeatStr("#",2*m-1));
  19.             System.out.print(repeatStr(" ",en));
  20.             System.out.print(repeatStr("#",2*m-1));
  21.             System.out.println(repeatStr(".",p));
  22.             p++;
  23.             en=en+2;
  24.             m--;
  25.             z++;
  26.         }
  27. en=en-2;
  28.         System.out.print(repeatStr(".",z));
  29.         System.out.print(repeatStr("#",2*m-1));
  30.         System.out.print(repeatStr(" ",(((en+2)-3))/2));
  31.         System.out.print("(@)");
  32.         System.out.print(repeatStr(" ",(((en+2)-3))/2));
  33.         System.out.print(repeatStr("#",2*m-1));
  34.         System.out.println(repeatStr(".",z));
  35.  
  36.  
  37.         z++;
  38.         int v=en;
  39.         for (int d=0;d<n-(s/2+1);d++)
  40.         {
  41.             System.out.print(repeatStr(".",z));
  42.             System.out.print(repeatStr("#",v-1));
  43.            System.out.print(repeatStr(" ",((4*n+1)-(2*z+2*(v-1)))));
  44.             System.out.print(repeatStr("#",v-1));
  45.             System.out.println(repeatStr(".",z));
  46.             z++;
  47.         v=v-2;}
  48.  
  49.         for(int j=0;j<q;j++)
  50.         {
  51.             System.out.print(repeatStr(".",c+1));
  52.             System.out.print(repeatStr("#",2*n-1));
  53.             System.out.println(repeatStr(".",c+1));
  54.             n=n-1;
  55.             c=c+1;}
  56.  
  57.     }
  58.     static String repeatStr(String str, int count ){
  59.         String text="";
  60.         {
  61.             for (int j = 0; j <count ; j++) {
  62.                 text=text+str;
  63.             }
  64.  
  65.         }
  66.         return text;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement