Matt23

Untitled

Oct 14th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. public class heli {
  2.  
  3.     public static void main(String[] args) {
  4.        // 3 - 80
  5.         StringBuilder sb = new StringBuilder();
  6.         int x;
  7.  
  8.         try
  9.         {
  10.             x = Integer.parseInt(args[0]);
  11.         }
  12.         catch (NumberFormatException e)
  13.         {
  14.             System.out.println("Podaj wartość liczbową!");
  15.             return;
  16.         }
  17.  
  18.         if (x < 3)
  19.         {
  20.             System.out.println("Podaj liczbę większą od 3");
  21.             return;
  22.         }
  23.  
  24.         for (int i = 1; i <= x; i++)
  25.         {
  26.             if (i - 1 == Math.floor(x / 2) && x % 2 == 1)
  27.             {
  28.                 for (int j = x; j > 0; j--)
  29.                 {
  30.                     sb.append('H');
  31.                 }
  32.                 sb.append('\n');
  33.             }
  34.             else if (x % 2 == 0 && (i == x / 2 || i == x / 2 + 1))
  35.             {
  36.                 for (int j = x; j > 0; j--)
  37.                 {
  38.                     sb.append('H');
  39.                 }
  40.                 sb.append('\n');
  41.             }
  42.             else
  43.             {
  44.                 if (x % 2 == 1)
  45.                 {
  46.                     sb.append('H');
  47.                     for (int j = x - 2; j > 0; j--)
  48.                     {
  49.                         sb.append(' ');
  50.                     }
  51.                     sb.append('H').append('\n');
  52.                 }
  53.                 else
  54.                 {
  55.                     sb.append('H').append('H');
  56.                     for (int j = x - 4; j > 0; j--)
  57.                     {
  58.                         sb.append(' ');
  59.                     }
  60.                     sb.append('H').append('H').append('\n');
  61.                 }
  62.             }
  63.         }
  64.         System.out.println(sb.toString());
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment