package four;import java.io.*;public class TestThrowException extends Exception{public static void square(double n) throw TestThrowException { if(n<0.0) throw new TestThrowException(); else Math.sqrt(n);}public static void main(String[] args)throws IOException{ double number = 0 ; TestThrowException tt = new TestThrowException() ; try { System.out.println("input double number"); BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine() ; number = Double.parseDouble(s); tt.square(number); } catch( TestThrowException e1) { System.out.println(e1.toString()+"输入数据有误"); }}}这段代码报错是TestThrowException不是throwable的求修改
1 回答
已采纳
Caballarii
TA贡献1123条经验 获得超629个赞
public static void square(double n) throw TestThrowException
应该是throws
添加回答
举报
0/150
提交
取消