楼主的代码中,整数a 为局部变量,并不是你的输入
不知道下面这个是否符合楼主的要求 public static String str = null;
public static Integer num = null;
public static void main(String[] args) {
System.out.println("请输入字符串");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
System.out.println("请输入整数");
num = sc.nextInt();
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
不知道下面这个是否符合楼主的要求 public static String str = null;
public static Integer num = null;
public static void main(String[] args) {
System.out.println("请输入字符串");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
System.out.println("请输入整数");
num = sc.nextInt();
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
解决方案 »
- A标签中传递的中文参数在另一个JSP页面用request.getParameter()接收时出现中文乱码问题
- 关于html显示的问题
- dom4j 能否获取某一个节点下的全部内容
- Xfire Webservice开发中的一个问题
- 输入localhost:8080/myjsp/firstjsp.jsp为什么有信息提示?
- 关于学习EJB2.0与3.0的问题
- 用struts标签实现 "显示查询结果" 页面??????????????????????????
- 请问在EJB中如何保存用户的Session信息.即希望保存类似于JSP中的Session信息.急!!!
- 为什么我的JBOSS启动后不能运行?(在线等,马上结)
- java.lang.RuntimeException:Unable to load library
- 如何打开MYeclipse的刚刚关闭页面
- 关于EL表达式判断字符串是否匹配+网页是否正确跳转
可以提供一个 BufferedReader版本的嘛?
public static String str = null;
public static Integer num = null;
public static void main(String[] args) throws IOException {
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
public static String str = null;
public static Integer num = null;
public static void main(String[] args) throws IOException {
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
public class Test {
public static void main(String[] args) {
String str = null;
Integer num = null;
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
}Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type IOException
Unhandled exception type IOException at Test.main(Test.java:14)java 版本是1.7的, 是不是必须捕捉异常才可以编译过去?java语法这么奇怪,难道异常必须捕捉?
public static void main(String[] args) throws IOException {
public static String str = null;
public static Integer num = null;
public static void main(String[] args) throws IOException {
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
public class Test {
public static void main(String[] args) {
String str = null;
Integer num = null;
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
}Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type IOException
Unhandled exception type IOException at Test.main(Test.java:14)java 版本是1.7的, 是不是必须捕捉异常才可以编译过去?java语法这么奇怪,难道异常必须捕捉?
package com.foo.proxy;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Test1 {
public static void main(String[] args) throws IOException {
String str = null;
Integer num = null;
System.out.println("请输入字符串");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
System.out.println("请输入整数");
num = Integer.parseInt(br.readLine());
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}
}
你的代码没问题啊! 你看一下你的14行对应的是哪一条语句~