Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

char inkrementieren?

Empfohlene Antworten

Hallo !

ich habe eine kleine Frage. Das Ergebnis einer Aufgabe sollte so aussehen:

*

**

***

****

*****

usw.

Also das Programm soll einfach für jede neue Zeile ein neues Zeichen (also ein Stern) hinzufügen. Die Anzahl Zeilen sind nicht fix. D.h. man soll die Zeilenanzahl über eine Console eingeben können.

Ich habe mir überlegt, dass ich das evtl. mit einer for-Schleife oder mit einer verschachtelten for-Schleife lösen kann. Das Problem ist, wie bringe ich Java dazu mir diese Sternchen nacheinander zu reihen??

Die Aufgabe sollte ohne Arrays lösbar sein.

Vielen Dank für jeden Tip.

Gruss

gipe

Du machst eine for-Schleife über die Zeilen. In dieser Schleife eine weitere for-Schleife, die dir n mal ein Sternchen auf dem Bildschirm ausgibt.

k.o.b

meinst Du sowas

int i = 1;

int j = 1;

char x = '*';

for (;i <10;i++) {

for (;j <10,j++) {

System.out.print(x);

}

}

hab'ich versucht, da Programm bringt mir aber nur 9x einzelne Sternchen also so:

*

*

*

*

*

*

*

*

*

was mach'ich falsch?

Vielen Dank.

gipe

Probiers mal mit

for (int nRow = 0; nRow < 10; nRow++)

{

for (int nColumn = 0; nColumn < nRow; nColumn++)

{

System.out.print("*");

}

System.out.println();

}

ich kanns auch mit einer while :D


public class Test{


	public static void main(String args[]){

		int zahl = 5;

		int zaehler1 = 1;

		int zaehler2 = 1;

		while(zaehler2<zahl+1){

			System.out.print("*");

			if(zaehler1==zaehler2){

				zaehler1 = 0;

				zaehler2++;

				System.out.println("");

			}

			zaehler1++;

		}

	}

}

Gruß Jaraz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.