debug6_2.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 29 行

JAVA
29
字号
package questions.c6;
interface IfaceDebug6_2 {
   public void f( int input );
}
class D62_OutOfRangeException extends Exception {
}
public class Debug6_2 implements IfaceDebug6_2 {
   public static final int MAX_X = 1000;
   public static final int MIN_X = 10;
   private int x;
   public void f( int input ) {
      setX( input );
   }
   public int getX() {
      return x;
   }
   public void setX( int value ) {
      if ( value >= MIN_X && value <= MAX_X ) {
         x = value;
      } else {
         throw new D62_OutOfRangeException();
      }
   }
   public static void main( String[] args ) {
      Debug6_2 a = new Debug6_2();
      a.f( 275 );
      System.out.println( a.getX() );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?