import java.io.*;
public class IOTest
{
public static void main (String[] args )
{
int b = 4;
System.out.print ("Input a integer:");
int a;
char[] c = new char[1];
try {
a = System.in.read();
if ((a > 57) || (a< 48))
System.out.println("输入错误,请输入数字");
c[0] = (char)a;
System.out.println (" " + (Integer.parseInt(new String(c)) + b));
} catch (IOException e){
System.out.println("Error of IO");
}
}
}我也才开始学java,不知哪位高手有更好的方法?
public class IOTest
{
public static void main (String[] args )
{
int b = 4;
System.out.print ("Input a integer:");
int a;
char[] c = new char[1];
try {
a = System.in.read();
if ((a > 57) || (a< 48))
System.out.println("输入错误,请输入数字");
c[0] = (char)a;
System.out.println (" " + (Integer.parseInt(new String(c)) + b));
} catch (IOException e){
System.out.println("Error of IO");
}
}
}我也才开始学java,不知哪位高手有更好的方法?
解决方案 »
- 极速表达式引擎——Fel0.5版本发布
- 以字符的方式进行读写文件,这样怎么写不出去?---------解决了,就及时结贴
- 菜鸟问题:关于用JAVA写的聊天室
- 还是swing那个输入窗口的问题(来吧,主要是散分)
- 一些swing的问题
- 请问各位大虾这个问题怎么解决?急!
- 谁知道人民大学附近哪有网通营业厅啊????
- 听说微软以后版本的Windows不支持Java,我这个初学者应该怎么办?
- 十万火急:各位大虾帮帮小弟吧。如何把informix数据库中的中文字段写如到一个文件中?
- 谁能教教我怎样使用jdb?
- 三天了,,三天没睡了,就因为这个程序,请各位帮帮忙看看!!!!!!
- 三天了,,三天没睡了,就因为这个程序,请各位帮帮忙看看!!!!!!
public class IOTest
{
public static void main ( String [ ] args )
{
int b;
System.out.print ( "Input a integer:" );
int a = Integer.parseInt ( System.in.read ( ) );
System.out.println ( a + b );
}
}
public class IOTest
{
public static void main ( String [ ] args ) throws IOException
{
int a=0,b=5; //要初始化的!
System.out.print ( "Input a integer:" );
try
{
a= Integer.parseInt( System.in.read( )); //这个可能会有异常抛出
}
catch(NumberFormationException e)
{
System.out.println("请确信输入的是数字!");
}
System.out.println ( a + b );
}
}试试吧! 应该可以了
public class IOTest
{ public static String keyin()
{
String s=" ";
try
{
BufferedReader one=new BufferedReader(new InputStreamReader(System.in));
s=one.readLine();
}
catch(IOException e) {System.out.println("There was wrong !");}
return s;
}
public static void main ( String [ ] args ) throws IOException
{
int a=0,b=5; //要初始化的!
System.out.print ( "Input a integer:" );
try
{
a= Integer.parseInt(keyin( )); //这个可能会有异常抛出
}
catch(NumberFormationException e)
{
System.out.println("请确信输入的是数字!");
}
System.out.println ( a + b );
}
}
这下试试吧!刚才实在是不好意思! 忘记了!
我又学到了东西!