你在plus内部实例化的对象,在方法结束后就释放掉了,result添加的值也并没有传给成员变量,
按照下边的改一下吧.- class Num {
- private StringBuilder decimalResult = new StringBuilder();;
- // 整数结果
- private StringBuilder intResult = new StringBuilder();;
- // 是否包含小数
- private boolean isDecimal = true;
- // 是否到整数了
- public Num() {
- }
- public void plus() {
- if (isDecimal) {
- plus(decimalResult);
- }
- plus(intResult);
- }
- private void plus(StringBuilder result) {
- // result = new StringBuilder();
- result.append("10000");
- }
- public StringBuilder getDecimalResult() {
- return decimalResult;
- }
- public StringBuilder getIntResult() {
- return intResult;
- }
- }
复制代码 |