当代码到达递归调用增量时,我收到了“找不到符号”的错误,但我不知道为什么?这是增量的代码。任何帮助将不胜感激。
public void increment() {
Integer first = 0;
Character ch = num.charAt(num.length()-1);
Integer last = Character.digit(ch, 10);
if (num.length() > 1)
{
if (last == 9) {
last = 0;
if (num.length() >= 2)
{
String temp = new String(num.substring(0, num.length()-2));
temp.increment();
}
else
{
last++;
}
}
}
else
{
if (last == 9)
{
last = 0;
first = 1;
}
else
{
last++;
}
}
String t = new String();
String x = new String();
t = last.toString();
x = first.toString();
if (first > 0)
{
num.concat(x);
}
num.concat(t);
}
编辑:我对Java非常陌生,因此您的答案越基础易懂越好。 好的,我收到的错误是: BigNatural.java.35: 找不到符号 符号方法increment() 位置:类java.lang.String temp.increment()
为了澄清其他问题,这是整个代码。
public class BigNatural {
private String num;
public BigNatural(String input) {
num = input;
}
public BigNatural(BigNatural input) {
num = input.toString();
}
public BigNatural(Integer input) {
num = input.toString();
}
public BigNatural() {
Integer i = 0;
num = i.toString();
}
public void increment() {
Integer first = 0;
Character ch = num.charAt(num.length()-1);
Integer last = Character.digit(ch, 10);
if (num.length() > 1)
{
if (last == 9) {
last = 0;
if (num.length() >= 2)
{
String temp = new String(num.substring(0, num.length()-2));
temp.increment();
}
else
{
last++;
}
}
}
else
{
if (last == 9)
{
last = 0;
first = 1;
}
else
{
last++;
}
}
String t = new String();
String x = new String();
t = last.toString();
x = first.toString();
if (first > 0)
{
num.concat(x);
}
num.concat(t);
}
public void decrement() {
Character ch = num.charAt(num.length()-1);
Integer last = Character.digit(ch, 10);
if(num.length() > 1)
{
if(last == 0)
{
String temp = new String(num.substring(0, num.length()-2));
temp.decrement();
}
else
{
last--;
}
}
else
{
if(last > 0)
{
last--;
}
else
{
last = 0;
}
}
String t = new String();
t = last.toString();
num.concat(t);
}
public String toString() {
return num;
}
公共类BigNatural {
private String num;
public BigNatural(String input) {
num = input;
}
public BigNatural(BigNatural input) {
num = input.toString();
}
public BigNatural(Integer input) {
num = input.toString();
}
public BigNatural() {
Integer i = 0;
num = i.toString();
}
public void increment() {
Integer first = 0;
Character ch = num.charAt(num.length()-1);
Integer last = Character.digit(ch, 10);
if (num.length() > 1)
{
if (last < 9) {
last++
}
else
{
last = 0;
if (num.length() >= 2)
{
String temp = new String(num.substring(0, num.length()-2));
temp.increment();
}
}
else {
last++;
}
}
else
{
if (last == 9)
{
last = 0;
first = 1;
}
else
{
last++;
}
}
String t = new String();
String x = new String();
t = last.toString();
x = first.toString();
if (first > 0)
{
num.concat(x);
}
num.concat(t);
}
public void decrement() {
Character ch = num.charAt(num.length()-1);
Integer last = Character.digit(ch, 10);
if(num.length() > 1)
{
if(last == 0)
{
String temp = new String(num.substring(0, num.length()-2));
temp.decrement();
}
else
{
last--;
}
}
else
{
if(last > 0)
{
last--;
}
else
{
last = 0;
}
}
String t = new String();
t = last.toString();
num.concat(t);
}
public String toString() {
return num;
}
}