Wednesday, 1 October 2014

JAVA PROGRAM TO READ A SINGLE CHARACTER FROM KEYBOARD

program:

import java.io.*;
public class Keyboard {
public static void main( String[ ] args ) {
try
{
System.out.print( "Please press any key: " );
char key = ( char )System.in.read( );
System.out.print( "The key pressed was: " + key );
}
catch( IOException ioe )
{
// do something about the exception
}
} // end of main
} // end of class definition

--------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Total Pageviews

108292