Throws Exception from main method - Java Object Oriented Design

Java examples for Object Oriented Design:main method

Description

Throws Exception from main method

Demo Code

import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    char c = '\u0000';
    System.out.print("Enter some text and then press Enter key: ");
    c = readChar();/*from   ww w. j  a  v a2 s .c om*/
    System.out.print("The first character you entered is: " + c);
  }
  public static char readChar() throws IOException {
    char c = '\u0000';
    int input = 0;
    input = System.in.read();
    if (input != -1) {
      c = (char)input;
    }
    return c;
  }
}

Result


Related Tutorials