I am receiving the error cannot find symbol when the code reaches the recursive call for increment and I have no idea why? Here is the code for increment. Any help will be greatly appreciated.
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);
}
EDIT: I'm really new to java so the more basic you can make your answers, the better. Ok so the error I am receiving is: BigNatural.java.35: cannot find symbol symbol method increment() location: class java.lang.String temp.increment()
And to clear up any other issues here is the whole code.
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;
}
} 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++
}
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;
}
}