我帮你改了改,问题应该解决了,问题原因是输入缓冲问题import java.io.*;public class t {
private BufferedReader breader= new BufferedReader( new InputStreamReader( System.in ) );private void showMainMenu() {
try {
System.out.println( "1 - \t2 - \t3 -" );
switch ( System.in.read() ) {
case '1': a(); break;
case '2': b(); break;
case '3': c(); break;
default: ;
}
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void a() {
System.out.println( "function a:" );
short s, j; try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void b() {
System.out.println( "function b:" );
short s, j; try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void c() {
System.out.println( "function c:" );
short s, j;
try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} public static void main( String[] args ) {
t test = new t();
test.showMainMenu();
}
}
private BufferedReader breader= new BufferedReader( new InputStreamReader( System.in ) );private void showMainMenu() {
try {
System.out.println( "1 - \t2 - \t3 -" );
switch ( System.in.read() ) {
case '1': a(); break;
case '2': b(); break;
case '3': c(); break;
default: ;
}
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void a() {
System.out.println( "function a:" );
short s, j; try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void b() {
System.out.println( "function b:" );
short s, j; try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} private void c() {
System.out.println( "function c:" );
short s, j;
try {
System.out.print( "s? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); s = Short.parseShort( breader.readLine() );
System.out.print( "j? " );
while (breader.ready()) //<------------------------ 清除输入缓冲区
breader.read(); j = Short.parseShort( breader.readLine() );
System.out.println( "s = " + s + "j = " + j );
} catch ( Exception e ) {
System.out.println( "an exception has occured." );
}
} public static void main( String[] args ) {
t test = new t();
test.showMainMenu();
}
}
解决方案 »
- 请求指导,如何将String里面的数字筛选出来返回一个数组?
- 回帖中引用功能实现--java正则表达式如何实现
- 求助有java绘图经验的朋友!!
- 能告诉我这怎样实现吗??
- java 对word 文件的读写问题,在线等待
- 为什么main(String args[])中的参数一定要?
- 哪里有关于BasicTableUI的详细说明介绍,最好有实例说明??谢谢
- 一个问题,万分紧急.请大家帮忙!!!多谢!!
- java读文件,比如有文件中有8个字节是double型,怎么它读出来,也转为double
- 在请教高手一个问题!!!
- 关于File中getPath()和getAbsolutePath()以及getCanonicalPath()各自的作用和区别?
- 求教:JPasswordText!
redhat linux 7.0 + jdk1.4.0_beta21 - 2 - 3 -
2
function b:
s? an exception has occured.你的结果怎样?打印出来看看?