67,512
社区成员
发帖
与我相关
我的任务
分享
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);
}
[/quote]
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语法这么奇怪,难道异常必须捕捉?
[/quote]
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行对应的是哪一条语句~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);
}
[/quote]
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 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) {
System.out.println("请输入字符串");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
System.out.println("请输入整数");
num = sc.nextInt();
System.out.println("字符串为 " + str + "\n" + "整数为 " + num);
}