下面的这个简单的Java程序怎么写

来源:百度知道 编辑:UC知道 时间:2024/05/14 22:11:38
我想 输入一个整数,运行再在控制台上打出这个数,下面的写法怎么修改
int s = System.in.read();
System.out.println(s);

现在是我输入6,结果打出来的是ascii码,请问怎么把s转换成int

Scanner s=new Scanner(System.in);
System.out.println(s.nextLine());

为什么不用Scanner来获取屏幕输出?这样你输入什么输出就是什么,不会变成ASCII码。

System.out.print("please Input one integer");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s="";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(s);
java的输入比较烦麻的

这个我偷来的..

public class Test {
public static void main(String[] args) {
Test.test(Integer.valueOf(args[0]));
}
public static void test(Integer arg) {
int i = Integer.parseInt(String.valueOf(arg));
System.out.println(i);
}
}

在eclipse中点选‘Run As’-> Run... -> Java Application -> New_configuration : 在 Main 选项卡里的‘Main class:’里 Search到你的类,然后在Arguments选项卡里的‘Program arguments:’里输入数字, 单击‘Run’按钮,即可以在‘Console’里面看到输出内容了。

String s = System.in.read();
Sys