You are not logged in.

  • Login

1

Thursday, February 23rd 2006, 11:10am

[Java] Ausgabe von Dreiecken & Rechtecken in Sternchen

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
/*
 * Created on 23.02.2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
 
/**
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class dreieck_rechteck {
 
	public static void main(String[] args) throws IOException {
 
		char auswahl3;
		do{
 
		BufferedReader eingabe2 = new BufferedReader (new InputStreamReader(System.in));
		System.out.println("\n\n@ by Marian | Tine");
		System.out.println("");
		System.out.println("Schönen Guten Tag der Herr!");
		System.out.println("Schönen Guten Tag holdes Weib!");
		System.out.println("Was wünschen Sie zeichnen zu lassen?");
		System.out.println("[1] Rechteck");
		System.out.println("[2] Dreieck");
		System.out.println("[3] Ausloggen");
		String eingabe = eingabe2.readLine();
		int auswahl = Integer.parseInt(eingabe);
 
		switch(auswahl){
			case 1:
	            System.out.print("Bitte geben Sie die Hoehe des Rechtecks ein: "); 
	            String hoeheein = eingabe2.readLine();
	            int hoehe = Integer.parseInt(hoeheein);
	            System.out.print("Bitte geben Sie die Breite des Rechtecks ein: "); 
	            String breiteein = eingabe2.readLine();
	            int breite = Integer.parseInt(breiteein);
 
	        	for (int i=0; i < hoehe; i++) {
	        	    System.out.print("*");	    
	        	    for (int j = 0; j < breite-2; j++) {
	        		if (i == 0 || i == hoehe - 1) {
	        		    System.out.print(" *");
	        		} else {
	        		    System.out.print("  ");
	        		}
	        	    }	    
	        	    System.out.println(" *");}
	        	    break;
			case 2:
	            int sternzahl=1;
 
	            System.out.print("Bitte geben Sie die Hoehe des gleichschenkligen Dreiecks ein: "); 
	            String max2 = eingabe2.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(" *");
	            }
	            break;
    }
		if (eingabe.length()==0)
			auswahl3 = 'w';
		else
			auswahl3 = eingabe.charAt(0);
		auswahl3 = Character.toLowerCase(auswahl3);
		}while(auswahl3 == 3);
}
		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);
        }
    }
}

This post has been edited 1 times, last edit by "Tesafilm" (Jan 24th 2012, 8:28pm)


Similar threads

Social bookmarks