byte[] bytes=new byte[100];
int count;
String s;
int i;
count=System.in.read(bytes);
s=new String(bytes,0,count - 2);
i=Integer.parseInt(s);//如果输入的是数字
int count;
String s;
int i;
count=System.in.read(bytes);
s=new String(bytes,0,count - 2);
i=Integer.parseInt(s);//如果输入的是数字
try{
System.in.read(bytes);
}
catch(IOException ex)
{
}
不然编译通不过
String str = br.reabLine();//读去一行
..........//定义一个字符串类型的变量
string input_num;
int num;
input_num=JOptionPane.showInputDialog("enter the number you want:");
num=Integer.parseInt(input_num);//num便是你所需的变量了
public class ReadInt
{
public static void main(String [] args)throws IOException
{
BufferedReader din = new BufferedReader(
new InputStreamReader(System.in));
System.out.print("anInt: ");
//"parseInt" parses the string argument as a signed
//decimal integer
int anInt = Integer.parseInt(din.readLine());
System.out.println(anInt); // read an float number
System.out.print("a Float: ");
float aFloat = Float.parseFloat(din.readLine());
System.out.println(aFloat); // read an double number
System.out.print("a Double: ");
double aDouble = Double.parseDouble(din.readLine());
System.out.println(aDouble);
}
}//下面这个从窗口接受数据
// Addition.javaimport javax.swing.JOptionPane; // import class JOptionPanepublic class Addition
{
public static void main(String [] args)
{ String firstNumber, // first string entered by user
secondNumber; // second string entered by user
int number1, // first number to add
number2, // second number to add
sum; // sum of number1 and number2 // read in first number from user as a string
firstNumber =
JOptionPane.showInputDialog("Enter first integer");
// read in second number from user as a string
secondNumber =
JOptionPane.showInputDialog("Enter second integer"); // convert numbers form type String to type int
number1 = Integer.parseInt(firstNumber);
number2 = Integer.parseInt(secondNumber); // add the numbers
sum = number1 + number2; // display the results
JOptionPane.showMessageDialog(null, "The sum is " + sum, "Results",
JOptionPane.PLAIN_MESSAGE);
System.exit(0); // terminate the program
}
}