Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Aufgabe2_lipTu {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Gene Sie eine Höhe ein: ");
- int height = sc.nextInt();
- if (height > 0 && height % 4 == 0){
- int r = 1;
- int temp = height / 2;
- if (r <= temp){
- int x = temp - r;
- int row = 0;
- while (x >= 1 && x >= row){
- for (int i = 0; i < x; i++){
- if (row > i){
- System.out.print(' ');
- }else{
- System.out.print('!');
- }
- }
- x -= 1;
- row++;
- if (x > row) {
- System.out.println();
- }
- }
- while (x < temp - 1){
- for (int i = 0; i < x; i++){
- if (row > i){
- System.out.print(' ');
- }else {
- System.out.print('!');
- }
- }
- x += 1;
- row--;
- System.out.println();
- }
- while (x >= 1 && x >= row){
- for (int i = 0; i < x; i++){
- if (row > i){
- System.out.print(' ');
- }else{
- System.out.print('!');
- }
- }
- x -= 1;
- row++;
- if (x > row) {
- System.out.println();
- }
- }
- while (x < temp){
- for (int i = 0; i < x; i++){
- if (row > i){
- System.out.print(' ');
- }else{
- System.out.print("!");
- }
- }
- x += 1;
- row--;
- System.out.println();
- }
- }
- }else{
- System.out.println("Falsche Eingabe!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement