Add chapters 18-20 for the java book
This commit is contained in:
24
Java-Kompendium/kap18/1/Schlafen.java
Normal file
24
Java-Kompendium/kap18/1/Schlafen.java
Normal file
@@ -0,0 +1,24 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Schlafen extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
var inputStream = new InputStreamReader(System.in);
|
||||
var bufferedReader = new BufferedReader(inputStream);
|
||||
int seconds;
|
||||
|
||||
System.out.println("Wieviele Sekunden soll ich warten?");
|
||||
try {
|
||||
var input = bufferedReader.readLine();
|
||||
seconds = Integer.parseInt(input);
|
||||
} catch (IOException exception) {
|
||||
seconds = 0;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(seconds * 1000);
|
||||
} catch (InterruptedException exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user