class OutBoundsException extends Exception{
 /**
  * 
  */
 private static final long serialVersionUID = 1L; OutBoundsException(String mes){
  super(mes);
 }
}
class Check{
 String ChecktheNum(int n) throws OutBoundsException{
  Integer N=new Integer(n);
  if(n>30||n<20)
   throw new OutBoundsException("the number is out of bound!!");
  else
   return "the number"+N.toString()+"is in the bounds";
 }
}
class Test {
 public static void main(String args[]) {
  Check c=new Check();
  try{
  System.out.println("以下是合法的数据报告:");
  System.out.println(c.ChecktheNum(25));
  System.out.println("以下是非法的数据报告:");
  System.out.println(c.ChecktheNum(5));
 }catch(OutBoundsException e){
  System.out.println(e.toString());
 }}
}return "the number"+N.toString()+"is in the bounds";中的N.toString()怎么解释  ??还有下面的 System.out.println(e.toString());是什么意思啊  为什么是e.toString()而不是c.toString()???? 急啊  !!!谢谢大虾们了

解决方案 »

  1.   

    N.toString() 将Integer类型的N转成String类型
    e.toString() 表示将异常转换成String类型方便输出
      

  2.   

    直接system.out.println(e)跟system.out.println(e.tostring)是 一样的结果
      

  3.   

    1、N.toString()调用N的toString()方法,toString()没有改写前的作用是打印出N所在的包名+类名;
    2、catch(OutBoundsException e){
      System.out.println(e.toString());
     }
    e.toString()是接受抛出的异常e信息。
      

  4.   

    Integer类的toString方法
    String toString() 
              返回一个表示该 Integer 值的 String 对象。 
    Throwable的toString方法(Exception继续Throwable)
    public String toString()返回此 throwable 的简短描述。结果是以下字符串的串联: 
    此对象的类的 name 
    ": "(冒号和一个空格) 
    调用此对象 getLocalizedMessage() 方法的结果 
    如果 getLocalizedMessage 返回 null,则只返回类名称。
    看完这2个API你就知道是什么意思了,请常备API,不懂及时查看,然后直接F3跳到代码里面去看看jdk是怎么实现的。
      

  5.   


    N为Integer类型    public String toString() {
            return String.valueOf(value);
        }
      

  6.   

    1,N.toString()是把N转换成string
    2,因为你catch(OutBoundsException e) 扑捉的是e 所以是是e.toString()而不是c.toString()
      

  7.   


    再弱弱的问一下啊  N.toString()去掉toString()和不去掉的打印结果一样  为什么啊??写上和不写上有区别吗??麻烦了啊 
      

  8.   


    N.toString()是String类型  N是Integer类型
    尽管System.out.println的输出结果一样,但这是System.out.println的作用,不能说明写与不写toString()没有区别System.out是PrintStream类型,可以看他的println的代码    public void println(Object x) {
            String s = String.valueOf(x);
            synchronized (this) {
                print(s);
                newLine();
            }
        }    public void print(String s) {
            if (s == null) {
                s = "null";
            }
            write(s);
        }也即,输出时是先将Integer转换成String s 然后输出
      

  9.   

    简单的来说吧,你的这句
    "the number"+N.toString()+"is in the bounds";
    +号前后连接的类型是   字符串+()+字符串。当然里面要转换成字符串形式喽。
    而 N是Integer类型,toString转换成N的String类型数值。
    而后的
     catch(OutBoundsException e){
    System.out. println(e.toString());
    }
    对象c是局部的 只能在他自己的大括号内,e.toString输出抛出异常的信息,e是OutBoundsException 的对象,
      

  10.   

    toString()方法会在两种情况下自动调用,一种是在System.out.print()方法,另外一种是在“+”号操作符被重载的情况下(即普通“+”号适用于代数运算神马的,而用于字符串中的“+”号的意义就是字符串的连接符。)所以在上面代码中N.toString()去掉与保留是没有区别滴- -