Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class heli {
- public static void main(String[] args) {
- // 3 - 80
- StringBuilder sb = new StringBuilder();
- int x;
- try
- {
- x = Integer.parseInt(args[0]);
- }
- catch (NumberFormatException e)
- {
- System.out.println("Podaj wartość liczbową!");
- return;
- }
- if (x < 3)
- {
- System.out.println("Podaj liczbę większą od 3");
- return;
- }
- for (int i = 1; i <= x; i++)
- {
- if (i - 1 == Math.floor(x / 2) && x % 2 == 1)
- {
- for (int j = x; j > 0; j--)
- {
- sb.append('H');
- }
- sb.append('\n');
- }
- else if (x % 2 == 0 && (i == x / 2 || i == x / 2 + 1))
- {
- for (int j = x; j > 0; j--)
- {
- sb.append('H');
- }
- sb.append('\n');
- }
- else
- {
- if (x % 2 == 1)
- {
- sb.append('H');
- for (int j = x - 2; j > 0; j--)
- {
- sb.append(' ');
- }
- sb.append('H').append('\n');
- }
- else
- {
- sb.append('H').append('H');
- for (int j = x - 4; j > 0; j--)
- {
- sb.append(' ');
- }
- sb.append('H').append('H').append('\n');
- }
- }
- }
- System.out.println(sb.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment