未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出
importjava.lang.*;importjava.io.*;classexponent{publicstaticvoidmain(Stringargs[]){Ob...
import java.lang.*;
import java.io.*;
class exponent
{
public static void main(String args[])
{
ObjectInputStream jin = new ObjectInputStream(System.in);
double tsampled = Double.Double(args[1]).doubleValue();
while(tsampled!=Double.NaN)
{
System.out.print(Double.valueOf(tsampled));
System.out.print(Math.getExponent(Double.valueOf(tsampled)));
tsampled = jin.readDouble();
}
}
};
//F:\doc\source codes\java\exponent>javac exponent.java
//exponent.java:9: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出
// ObjectInputStream jin = new ObjectInputStream(System.in);
// ^
//exponent.java:10: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出
// double tsampled = jin.readDouble();
// ^
//2 错误
//
//F:\doc\source codes\java\exponent>
顺便问一下,System.in怎么用? 展开
import java.io.*;
class exponent
{
public static void main(String args[])
{
ObjectInputStream jin = new ObjectInputStream(System.in);
double tsampled = Double.Double(args[1]).doubleValue();
while(tsampled!=Double.NaN)
{
System.out.print(Double.valueOf(tsampled));
System.out.print(Math.getExponent(Double.valueOf(tsampled)));
tsampled = jin.readDouble();
}
}
};
//F:\doc\source codes\java\exponent>javac exponent.java
//exponent.java:9: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出
// ObjectInputStream jin = new ObjectInputStream(System.in);
// ^
//exponent.java:10: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出
// double tsampled = jin.readDouble();
// ^
//2 错误
//
//F:\doc\source codes\java\exponent>
顺便问一下,System.in怎么用? 展开
展开全部
public static void main(String args[]) throws IOException { //你这里写错了
ObjectInputStream jin = new ObjectInputStream(System.in);
double tsampled = Double.valueOf(args[0]); //你这里方法写错了,而且貌似数组下标也用错了
while (tsampled != Double.NaN) {
System.out.print(Double.valueOf(tsampled));
System.out.print(Math.getExponent(Double.valueOf(tsampled)));
tsampled = jin.readDouble();
}
}
仅检查语法,没有做其他检查
这是根据你的需求写的代码(我理解中的你的需求):
public static void main(String args[]) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line = reader.readLine();
while (line != null) {
double tsampled = Double.valueOf(line);
System.out.println(tsampled);
System.out.println(Math.getExponent(tsampled));
line = reader.readLine();
}
}
ObjectInputStream jin = new ObjectInputStream(System.in);
double tsampled = Double.valueOf(args[0]); //你这里方法写错了,而且貌似数组下标也用错了
while (tsampled != Double.NaN) {
System.out.print(Double.valueOf(tsampled));
System.out.print(Math.getExponent(Double.valueOf(tsampled)));
tsampled = jin.readDouble();
}
}
仅检查语法,没有做其他检查
这是根据你的需求写的代码(我理解中的你的需求):
public static void main(String args[]) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line = reader.readLine();
while (line != null) {
double tsampled = Double.valueOf(line);
System.out.println(tsampled);
System.out.println(Math.getExponent(tsampled));
line = reader.readLine();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将代码放到try catch块中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加一段try就好了,因为JAVA程序必须对可能发生的异常进行处理
修改如下:
public int readFile(String sFileName)
{
BufferedReader br = new BufferedReader(new FileReader(sFileName));
try{
String sRead = br.readLine();
int iCount = Integer.parseInt(sRead);
br.close();
}
catch(Exception e){
e.printStacktrace();
}
return iCount;
}
修改如下:
public int readFile(String sFileName)
{
BufferedReader br = new BufferedReader(new FileReader(sFileName));
try{
String sRead = br.readLine();
int iCount = Integer.parseInt(sRead);
br.close();
}
catch(Exception e){
e.printStacktrace();
}
return iCount;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
貌似你用记事本写的代码?
木有错误提示?
木有错误提示?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询