一个数字读取问题??
public class Try
{public static void main(String args[])
throws java.io.IOException
{int x;
x=System.in.read();
System.out.println(+x);
}
}
我要使输入一个整数,再输出它,怎么写???,上面的个程序为什么总是输出它的ASCII值呢???
多谢各位了
问题点数:20、回复次数:8Top
1 楼gxl123(苛夲另手我蔷薇彦觚你遥)回复于 2006-04-20 21:51:36 得分 0
版主能不能帮我强行结贴呀,谢谢了
自己答了算了
//显示输入面板的例子
import javax.swing.JDialog;
import javax.swing.JOptionPane;
public class JOptionPane
{
public static void main(String[] args)
{String A=JOptionPane.showInputDialog("please inprint number!");
int B=Integer.parseInt(A);
int C=B;
JOptionPane.showMessageDialog(null, C, "B", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}Top
2 楼btb368()回复于 2006-04-21 08:16:59 得分 4
int x;
x=System.in.read();
System.out.println(+x);
换成
String x;
x=System.in.readline();
System.out.println(x);
Top
3 楼hanjienihao1()回复于 2006-04-21 09:38:14 得分 4
import java.io.*;
class AAA
{
public static void main(String[] args)
{
try{
int x;
x=System.in.read();
System.out.println((char)x);
} catch(Exception e) {
e.printStackTrace();
}
}
}
100%好使,多谢,尽快散分!:)Top
4 楼hanjienihao1()回复于 2006-04-21 09:40:12 得分 4
import javax.swing.JDialog;
import javax.swing.JOptionPane;
public class JOptionPane {
public static void main(String[] args) {
String A=JOptionPane.showInputDialog("please inprint number!");
int B=Integer.parseInt(A);
int C=B;
JOptionPane.showMessageDialog(null, C, "B", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
都不能用,我以为是什么好东西Top
5 楼xxedge(好钢用在刀刃上)回复于 2006-04-21 10:39:17 得分 4
楼上的,版主的程序有点问题,修改一下就可以了
int C=B;修改为Integer C = new Integer(B);
程序如下:
import javax.swing.JDialog;
import javax.swing.JOptionPane;
public class tttt {
public static void main(String[] args) {
String A=JOptionPane.showInputDialog("please inprint number!");
int B=Integer.parseInt(A);
Integer C=new Integer (B);
JOptionPane.showMessageDialog(null, C, "B", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}Top
6 楼cyxlsm()回复于 2006-04-21 10:52:01 得分 2
三楼的程序OK!Top
7 楼sheep219(sheep219)回复于 2006-04-21 11:24:22 得分 1
数据类型不匹配,System.in.read();返回的是String型的.int x为int 型肯定不行了.Top
8 楼ysd126()回复于 2006-04-21 11:38:18 得分 1
import java.io.*;
public class T {
public static void main(String[] args)
{
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true)
{
String x = br.readLine();
if(x.equals("exit"))
break;
System.out.println(x);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}Top




