?? myinteger.java
字號:
//Exercise 7.5
public class MyInteger {
//instance variable
private int value;
//constructor
public MyInteger(int value){
this.value = value;
}
//getter and setter
public int getValue(){
return value;
}
public void setValue(int value){
this.value = value;
}
//other public methods
public boolean isEven(){//do not need the parameter here
/*if (value %2 == 0 ){
}*/
return (value % 2 == 0);
}
public boolean isOdd(){//do not need the parameter here
return (value % 2 == 0);
}
public boolean equals(int another){
return (value == another);
}
public boolean equals(MyInteger another){//another is an instance in MyInteger
return (this.value == another.value);
}
public String toString(){
return value + "";//convert int(value) to string
}
//return the current instance
//i1.add(i2),update i1 and return i1
public MyInteger add(MyInteger another){
this.value += another.value;
return this;
}
public MyInteger multiply(MyInteger another){
this.value *= another.value;
return this;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -