>41
// ASCIIDemo.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @see ttp://www.shibu.jp/cppreference/ascii.html
*/
public class ASCIIDemo {
public static void main(String[] args) {
System.out.println( "exitを入力すると終了." );
while( true ) {
System.out.print( "> " );
try {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );
String line = br.readLine();
if( line.equals( "exit" ) ) System.exit( 0 );
else if( line.length() != 1 ) throw new IllegalArgumentException( "入力文字は1文字で:" + line );
else {
int ascii = new Character(line.toCharArray()[0]).hashCode();
if( ascii > 127 ) throw new IllegalArgumentException( "ASCIIコードがありません:" + line );
else System.out.println( ascii );
}
} catch( IOException ioe ) {
ioe.printStackTrace();
} catch( IllegalArgumentException iae ) {
System.err.println( iae.getMessage() );
}
}
}
}