Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Aufgabe2_lipTu {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.println("Gene Sie eine Höhe ein: ");
  8.  
  9.         int height = sc.nextInt();
  10.         if (height > 0 && height % 4 == 0){
  11.  
  12.             int r = 1;
  13.             int temp = height / 2;
  14.             if (r <= temp){
  15.                 int x = temp - r;
  16.                 int row = 0;
  17.                 while (x >= 1 && x >= row){
  18.                     for (int i = 0; i < x; i++){
  19.  
  20.                         if (row > i){
  21.                             System.out.print(' ');
  22.                         }else{
  23.                             System.out.print('!');
  24.                         }
  25.                     }
  26.                     x -= 1;
  27.                     row++;
  28.  
  29.                     if (x > row) {
  30.                         System.out.println();
  31.                     }
  32.                 }
  33.                 while (x < temp - 1){
  34.                     for (int i = 0; i < x; i++){
  35.  
  36.                         if (row > i){
  37.                             System.out.print(' ');
  38.                         }else {
  39.                             System.out.print('!');
  40.                         }
  41.                     }
  42.                     x += 1;
  43.                     row--;
  44.                     System.out.println();
  45.  
  46.                 }
  47.                 while (x >= 1 && x >= row){
  48.                     for (int i = 0; i < x; i++){
  49.  
  50.                         if (row > i){
  51.                             System.out.print(' ');
  52.                         }else{
  53.                             System.out.print('!');
  54.                         }
  55.                     }
  56.                     x -= 1;
  57.                     row++;
  58.                     if (x > row) {
  59.                         System.out.println();
  60.                     }
  61.  
  62.                 }
  63.                 while (x < temp){
  64.                     for (int i = 0; i < x; i++){
  65.                         if (row > i){
  66.                             System.out.print(' ');
  67.                         }else{
  68.                             System.out.print("!");
  69.                         }
  70.                     }
  71.                     x += 1;
  72.                     row--;
  73.                     System.out.println();
  74.  
  75.                 }
  76.             }
  77.         }else{
  78.             System.out.println("Falsche Eingabe!");
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement