Advertisement
du4ko

ExampPrepJavaPictureTheDiamond

May 21st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. enter odd numer and get this (example 7)
  2.  ---*---
  3.  --*-*--
  4.  -*---*-
  5.  *-----*
  6.  -*---*-
  7.  --*-*--
  8.  ---*---
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. package FinalCSharpTest;
  18.  
  19. import java.util.Scanner;
  20.  
  21. public class TheExplorer {
  22.  
  23.     public static void main(String[] args) {
  24.         Scanner scan = new Scanner(System.in);
  25.         int n = scan.nextInt();
  26.         char core = '*';
  27.         char outin = '-';
  28.         int statOne = 1;
  29.         int statTwo = n/2-1;
  30.         // top
  31.         topbottom(n/2, outin);
  32.         topbottom(1, core);
  33.         topbottom(n/2, outin);
  34.         System.out.println();
  35.         for (int i = 0; i < n/2-1; i++) {
  36.             coreString(statTwo, outin);
  37.             coreString(1, core);
  38.             coreString(statOne, outin);
  39.             coreString(1, core);
  40.             coreString(statTwo, outin);
  41.             statOne+=2;
  42.             statTwo--;
  43.             System.out.println();
  44.         }
  45.         //mid
  46.        
  47.         topbottom(1, core);
  48.         topbottom(n-2, outin);
  49.         topbottom(1, core);
  50.         System.out.println();
  51.         for (int i = 0; i < n/2-1; i++) {
  52.             statOne-=2;
  53.             statTwo++;
  54.             coreString(statTwo, outin);
  55.             coreString(1, core);
  56.             coreString(statOne, outin);
  57.             coreString(1, core);
  58.             coreString(statTwo, outin);
  59.            
  60.             System.out.println();
  61.         }
  62.         //bottom
  63.        
  64.         topbottom(n/2, outin);
  65.         topbottom(1, core);
  66.         topbottom(n/2, outin);
  67.     }
  68.  
  69.       static void coreString(int n , char ch) {
  70.         for (int i = 0; i <n; i++) {
  71.             System.out.print(ch);
  72.         }
  73.        
  74.     }
  75.  
  76.     static void topbottom(int n , char ch) {
  77.         for (int i = 0; i <n; i++) {
  78.             System.out.print(ch);
  79.         }
  80.        
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement