|
|
Java Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public class gleichschenkliges_Dreieck { /** * @author Torben Brodt * @version 1.0 * * <p />Malt ein Dreieck aus Sternen (Leerzeichen helfen bei der Ausrichtung) * <p />Funktioniert mit Java <= 1.5 * */ public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Bitte geben Sie die Hoehe des gleichschenkligen Dreiecks ein: "); int eingabe = input.nextInt(); int anzahl = eingabe; //Nullen sind Leerzeichen String nullen, sterne=""; while(anzahl > 0) { sterne += (anzahl == eingabe) ? "*" : "**"; anzahl--; nullen = ""; for(int i=0; i<anzahl; i++) nullen += " "; System.out.println(" "+nullen+sterne); } } } |
|
|
Java Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public class A4_Dreieck_Sternchen { /** * @param args */ public static void main(String[] args) { int max = 15, sternzahl=1; // Ausgabe signs(' ', max/2+1); System.out.println("*"); for (int count=max/2; count >= 0; count--) { sternzahl += 2; signs(' ', count); signs('*', sternzahl); System.out.println(); } } static void signs(char sign, int count) { for (int i=0; i<count; i++) System.out.print(sign); } } |
|
|
Java Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public class A4b_Dreieck_Sternchen { /** * @param args */ public static void main(String[] args) { int max = 15, sternzahl=1; // Ausgabe signs(' ', max/2+1, false); System.out.println("*"); for (int count=max/2; count >= 0; count--) { sternzahl += 2; signs(' ', count, false); signs('*', sternzahl, (count == 0)); System.out.println(); } } static void signs(char sign, int count, boolean max) { for (int i=0; i<count; i++) { char newsign = (sign == '*' && i > 0 && i < count-1 && max == false) ? ' ' : sign; System.out.print(newsign); } } } |
|
|
Java Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class gleichschenkliges_Dreieck2 { public static void main(String[] args) throws IOException { int sternzahl=1; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Bitte geben Sie die Hoehe des gleichschenkligen Dreiecks ein: "); String max2 = input.readLine(); int max = Integer.parseInt(max2); // Ausgabe signs(' ', max, 0); System.out.println("*"); for (int count=max-1; count > 1; count-=1) { sternzahl += 2; signs(' ', count, 0); signs('*', sternzahl, max+999); System.out.println(); } for (int bla=max; bla>0; bla-=1) { System.out.print(" *"); } } static void signs(char sign, int count, int max) { for (int i=0; i<count; i++) { char newsign = (sign == '*' && i > 0 && i < count-1 && count != max) ? ' ' : sign; System.out.print(newsign); } } } |
|
|
Java Quellcode |
1 |
(anzahl == eingabe) ? "*" : "**" |
|
|
Java Quellcode |
1 2 3 4 5 6 7 8 |
if(anzahl == eingabe) { sterne = sterne + "*"; } else { sterne = sterne +"**"; } |
|
|
Java Quellcode |
1 |
sterne += (anzahl == eingabe) ? "*" : "**"; |
|
|
Java Quellcode |
1 2 3 4 5 |
while(anzahl > 0) { sterne += (anzahl == eingabe) ? "*" : "**"; System.out.println(" "+sterne); anzahl--; } |
|
|
Source code |
1 2 3 4 5 |
* *** ***** ******* ********* |
|
|
Source code |
1 2 3 4 5 |
[ 5]* [ 4]*** [ 3]***** [ 2]******* [1]********* |
|
|
Java Quellcode |
1 2 |
for(int i=0; i<anzahl; i++) nullen += " "; |