Advertisement
dimipan80

C#Exams 3. Wine Glass (on Java Code)

Aug 24th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _3_WineGlass {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int height = scan.nextInt();
  9.  
  10.         int asterisks = height - 2;
  11.         String asteriskSeq = newString('*', asterisks);
  12.         System.out.printf("\\%s/\n", asteriskSeq);
  13.         String outerDotSeq;
  14.         for (int row = 1; row < (height / 2); row++) {
  15.             asterisks -= 2;
  16.             outerDotSeq = newString('.', row);
  17.             asteriskSeq = newString('*', asterisks);
  18.             System.out.printf("%1$s\\%2$s/%1$s\n", outerDotSeq, asteriskSeq);
  19.         }
  20.  
  21.         outerDotSeq = newString('.', (height - 2) / 2);
  22.         for (int row = (height / 2); row < height; row++) {
  23.             if (row == (height - 1) || (height >= 12 && row >= (height - 2))) {
  24.                 System.out.println(newString('-', height));
  25.             } else {
  26.                 System.out.printf("%1$s||%1$s\n", outerDotSeq);
  27.             }
  28.         }
  29.     }
  30.  
  31.     private static String newString(char ch, int size) {
  32.         StringBuilder sb = new StringBuilder();
  33.         for (int i = 0; i < size; i++) {
  34.             sb.append(ch);
  35.         }
  36.  
  37.         return sb.toString();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement