| Author |
how to read Character input from console
|
Manikanta Sabarish
Greenhorn
Joined: Jul 18, 2005
Posts: 14
|
|
Hello Being a beginner in java,I am trying to read character input from the console and want to implement switch-case based upon the character input. I had tried searching this forum and couldn't exactly find a solution. char c= (char) System.in.read() ,tried this,but it throws an IOexception. I will greatly appreciate if someboody could guide me for the possible solution. Thanks Code: Want to read character input like +,-,*.. from the console. //char c = (char)System.in.read(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char c = (char)br.read(); switch(c){ case '+': add(num1,num2); break; case '*': multiply(num1,num2); break; case '-': subtract(num1,num2); break; case '/': divide(num1,num2); break;
|
 |
Manikanta Sabarish
Greenhorn
Joined: Jul 18, 2005
Posts: 14
|
|
sorry about that. It did worked using both ways to read a character input. char c = (char)System.in.read(); or BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char c = (char)br.read(); you should throw IOException while using both ways. I request the Moderator or administrator to please delete this post,unless u feel this is anything informative. Thank you. [ September 07, 2005: Message edited by: Manikanta Sabarish ]
|
 |
 |
|
|
subject: how to read Character input from console
|
|
|