Welcome, guest! Login / Register - Why register?
[email protected] webmail now available. Want one? Go here.

Paste

N/A
Pasted as Java by loli ( 9 years ago )
package blatt4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Aufgabe 3
 * 
 * Raute aus Sternchen mit Benutzereingabe und Error-Script
 */

/**
 * @author none
 * 
 */
public class Sheet4Task3 {

 /**
  * @param args
  * @throws IOException
  * @throws NumberFormatException
  */
 public static void main(String[] args) throws NumberFormatException,
   IOException {

  BufferedReader input = new BufferedReader(new InputStreamReader(
    System.in));

  int n;

  // UserInput DiamondHight
  System.out.println("Raute in Sternchen generieren...");
  System.out.println("Bitte geben Sie die Höhe der Raute ein!");
  System.out.print("DiamondHight: ");
  n = Integer.parseInt(input.readLine());

  // ErrorScript
  while ((n < 0) | (n % 2 == 0)) {
   System.out.println("ERROR: Zahl ist gerade oder negativ!");
   System.out.println("Bitte geben Sie die Höhe der Raute ein!");
   System.out.print("DiamondHight: ");
   n = Integer.parseInt(input.readLine());
  }

  System.out.println();
  

  // SystemOut Diamond
  n /= 2;
  for (int i = -n; i <= n; i++) {
   for (int j = -n; j <= n; j++) {
    if ((Math.abs(i) + Math.abs(j)) <= n)
     System.out.print("*");
    else
     System.out.print(" ");
   }
   System.out.println();
  }

 }

}

 

Revise this Paste

Parent: 25467
Your Name: Code Language: