Navigation überspringen

Der Einfachste Weg...

Vorwissen

Ausgabe

Wir haben bereits die einfachste Bildschirmausgabe System.out in der Miniapplikation HalloWelt.java kennengelernt.

 

 1 package hallowelt;
 2 
 3 public class HalloWelt {
 4 
 5     public static void main(String[] args) {
 6         
 7         System.out.println("Hallo Welt!");
 8         
 9     }//public static void main(String[] args)
10     
11 }//public class HalloWelt

 

Die Methode println gibt nun eine ganze Zeichenkette aus. und wird mit einem Zeilenumbruch beendet. Diese Methode ist in der Klasse System.out enthalten.

 

Eingabe

Das Gegenstück heißt System.in .

 

 1 package hallowelt;
 2 
 3 import java.io.IOException;
 4 
 5 public class HalloWelt {
 6 
 7     public static void main(String[] args) throws IOException {
 8         
 9         int ausgabe = System.in.read();
10         System.out.println(ausgabe);
11         
12     }//public static void main(String[] args)
13     
14 }//public class HalloWelt

 Die Methode read() liest exakt ein einziges Zeichen ein.