Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
import java.io.BufferedInputStream;
import java.io.IOException;

public final class InputLibrary{
	
	private static BufferedInputStream in = new BufferedInputStream(System.in);

  public static char getChar()throws IOException {
    int input = in.read();
    if(input==-1){
    	throw new IOException();
    }
    in.skip(1); //this line now necessary to go to the next line
                //in the previous example code deceptively worked without it
    return (char)input;
  }

  public static void main(String[] args)throws IOException {
    System.out.print("Enter first initial: ");
    char first=getChar();
    System.out.println("Your first initial is "+first);
    System.out.print("Enter last initial: ");
    char last=getChar();
    System.out.println("Your last initial is "+last);
  }
}

...

References

Wiki Markup
\[[API 0506|AA. Java References#API 0506]\] [class ScannerBufferedInputStream|http://java.sun.com/javase/56/docs/api/java/io/BufferedInputStream.html]