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.

benutzereingabe + ausgabe mit threads

Empfohlene Antworten

Veröffentlicht

Hallo,

ich hab folgende klasse geschrieben: (soll den text 3 mal ausgeben, 3 sek abstand)

class TextThread extends Thread {
String text;

public TextThread(String text) {
this.text = text;
}

public void run() {
for(int i = 0; i < 3; i++) {
try {
sleep(3000);
}
catch(InterruptedException e) {
}
System.out.println(text);
}
}
}[/PHP]

jetzt will ich dass diese ausgabe vom eingabe des benutzers passiert

[PHP]import java.io.*;

class Eingabe extends Thread {



public void run() {
// while(...)
// {
String line;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in) );


try{
line = in.readLine();
}

catch (IOException e) {System.out.println(" Fehler: "+ e.getMessage()) ;}

//}


}


public static void main (String args[]){

Eingabe ein = new Eingabe();
ein.start();
TextThread java;
//--> java = new TextThread(???????);
java.start();



}
}

ich weiß nicht wie meine eingabe an java = new TextThread(???????); übergeben wird, dachte ich kann da line eintragen, geht aber nicht.

danke

  • Autor

ok hab das problem gelöst.

(string als grobale deklariert und aufruf in der klasse eingabe gestartet)

jetzt will ich dass man so lange was eingibt, bist man nichts eingibt und enter drückt.

do{

....

}

while(line==null);

geht nicht, warum?

jetzt will ich dass man so lange was eingibt, bist man nichts eingibt und enter drückt.

do{

....

}

while(line==null);

geht nicht, warum?

Denk' mal ganz scharf nach, welche Eingabe ein Benutzer macht, der nichts außer ENTER eingibt ...

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.