How to process only single charater as and when user enters it on the console in java -
is there way of processing single charater in java using simple program?
i should ask user enter charater, when user enters character java program should process before user enters next character, , should give immediate response user on character has entered.i tried
public class inputchar { public static void main(string args[]) { system.out.printf("enter char ==> "); try { char temp = (char) system.in.read(); system.out.printf("you entered: " + temp + "\n"); } catch (exception exe) { exe.printstacktrace(); } } }
but still in above program whenever user enters character not printing character right away.in above program when user presses 'enter' key program processes whatever has entered.is there anyway without pressing 'enter' key process first charater input user has entered.
first system.in.read() gets input user. allows user enter number of characters.
then converting char. takes first character alone.
when press enter input taken process.
so when press enter key next line processed.
though if want have still "enter key process", apply conditions when input user
Comments
Post a Comment