05.0 Java Notes‎ > ‎

Java: Input and output

Input from the Keyboard - Using Scanner

Numbers

  Java Statment
import statement needed:  import java.util.Scanner; 
Scanner variable needed Scanner kb/        // kb used a a short form for keyboard
the scanner must be created in the program kb = new Scanner(System.in);
 the two lines above may be combined into one statement Scanner kb =  new Scanner(System.in);
accepts an integer from the keyboard int x = kb.nextInt(); 

Sample Program:  Java: Min, Max, Average

Text

  Java Statment
import statement needed:  import java.util.Scanner; 
Scanner variable needed Scanner kb/        // kb used a a short form for keyboard
the scanner must be created in the program kb = new Scanner(System.in);
 the two lines above may be combined into one statement Scanner kb =  new Scanner(System.in);
 accepts text from the keyboard String str = kb.nextLine(); 

Input from the keyboard - Using InputDialogueBox

Sample Program:  1.2 Java Input Dialog Boxes

Output to the Monitor

System.out.println

System.out.print

Format using:
    Control Characters: 1.7 Java Format using System.out.print

Text Files

Java: Text file - Input

Binary Files -- files of objects

Objects are read and written via Object Streams.
Objects that are to use the Object Stream must implements java.io.Serializable